Skip to content

Commit

Permalink
style: I prefer audio_duration to audio_length
Browse files Browse the repository at this point in the history
  • Loading branch information
joanise committed Sep 28, 2022
1 parent 41d5912 commit 728991f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
12 changes: 7 additions & 5 deletions readalongs/web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ def create_grammar(xml):
class ConvertRequest(BaseModel):
"""Convert Request contains the RAS-processed XML and SMIL alignments"""

audio_length: float = Field(
audio_duration: float = Field(
example=2.01,
gt=0.0,
title="The length of the audio used to create the alignment, in seconds.",
title="The duration of the audio used to create the alignment, in seconds.",
)

output_format: str = Field(
Expand Down Expand Up @@ -291,7 +291,7 @@ async def convert_alignment(input: ConvertRequest) -> ConvertResponse:
Encoding: all input and output is in UTF-8.
Args (as dict items in the request body):
- audio_length: duration in seconds of the audio file used to create the alignment
- audio_duration: duration in seconds of the audio file used to create the alignment
- output_format: one of TextGrid, eaf, srt, vtt
- xml: the XML file produced by /assemble
- smil: the SMIL file produced by SoundSwallower(.js)
Expand Down Expand Up @@ -333,14 +333,16 @@ async def convert_alignment(input: ConvertRequest) -> ConvertResponse:

output_format = input.output_format.lower()
if output_format == "textgrid":
save_label_files(words, parsed_xml, input.audio_length, prefix, "textgrid")
save_label_files(
words, parsed_xml, input.audio_duration, prefix, "textgrid"
)
return ConvertResponse(
file_name="aligned.TextGrid",
file_contents=slurp_file(prefix + ".TextGrid"),
)

elif output_format == "eaf":
save_label_files(words, parsed_xml, input.audio_length, prefix, "eaf")
save_label_files(words, parsed_xml, input.audio_duration, prefix, "eaf")
return ConvertResponse(
file_name="aligned.eaf",
file_contents=slurp_file(prefix + ".eaf"),
Expand Down
18 changes: 9 additions & 9 deletions test/test_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_debug(self):

def test_convert_to_TextGrid_errors(self):
request = {
"audio_length": 83.1,
"audio_duration": 83.1,
"output_format": "TextGrid",
"xml": "this is not XML",
"smil": self.hej_verden_smil,
Expand All @@ -161,7 +161,7 @@ def test_convert_to_TextGrid_errors(self):
self.assertEqual(response.status_code, 422, "Invalid XML should fail.")

request = {
"audio_length": 83.1,
"audio_duration": 83.1,
"output_format": "TextGrid",
"xml": self.hej_verden_xml,
"smil": "This is not SMIL",
Expand All @@ -170,7 +170,7 @@ def test_convert_to_TextGrid_errors(self):
self.assertEqual(response.status_code, 422, "Invalid SMIL should fail.")

request = {
"audio_length": -10.0,
"audio_duration": -10.0,
"output_format": "TextGrid",
"xml": self.hej_verden_xml,
"smil": self.hej_verden_smil,
Expand All @@ -180,7 +180,7 @@ def test_convert_to_TextGrid_errors(self):

def test_convert_to_TextGrid(self):
request = {
"audio_length": 83.1,
"audio_duration": 83.1,
"output_format": "TextGrid",
"xml": self.hej_verden_xml,
"smil": self.hej_verden_smil,
Expand Down Expand Up @@ -246,7 +246,7 @@ class = "IntervalTier"

def test_convert_to_eaf(self):
request = {
"audio_length": 83.1,
"audio_duration": 83.1,
"output_format": "eaf",
"xml": self.hej_verden_xml,
"smil": self.hej_verden_smil,
Expand All @@ -258,7 +258,7 @@ def test_convert_to_eaf(self):

def test_convert_to_srt(self):
request = {
"audio_length": 83.1,
"audio_duration": 83.1,
"output_format": "srt",
"xml": self.hej_verden_xml,
"smil": self.hej_verden_smil,
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_convert_to_srt(self):
def test_convert_to_vtt(self):
request = {
"encoding": "utf-8", # for bwd compat, make sure the encoding is allowed but ignored
"audio_length": 83.1,
"audio_duration": 83.1,
"output_format": "vtt",
"xml": self.hej_verden_xml,
"smil": self.hej_verden_smil,
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_convert_to_vtt(self):

def test_convert_to_bad_format(self):
request = {
"audio_length": 83.1,
"audio_duration": 83.1,
"output_format": "not_a_known_format",
"xml": self.hej_verden_xml,
"smil": self.hej_verden_smil,
Expand All @@ -343,7 +343,7 @@ def test_convert_to_bad_format(self):
self.assertEqual(response.status_code, 422)

request = {
"audio_length": 83.1,
"audio_duration": 83.1,
# "output_format" just missing
"xml": self.hej_verden_xml,
"smil": self.hej_verden_smil,
Expand Down

0 comments on commit 728991f

Please sign in to comment.