Skip to content

Commit

Permalink
Fix double-transcription bug. Transcribe in /speech.api if format i…
Browse files Browse the repository at this point in the history
…s text.
  • Loading branch information
sultur committed Sep 13, 2023
1 parent fed7f64 commit 04eb989
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions routes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,12 @@ def query_api(version: int = 1) -> Response:
# Create audio data
TTS_SETTINGS.AUDIO_DIR = TTS_AUDIO_DIR
tts_options = TTSOptions(voice=vid, speed=voice_speed)
tts_output: TTSOutput = tts_to_file(v, tts_options=tts_options)
# Set transcribe to False here, as we don't need to transcribe twice
tts_output: TTSOutput = tts_to_file(
v,
tts_options=tts_options,
transcribe=False,
)
url = tts_output.file.as_uri()
if url:
result["audio"] = _audio_file_url_to_host_url(url, request)
Expand Down Expand Up @@ -570,10 +575,16 @@ def speech_api(version: int = 1) -> Response:
if not text:
return better_jsonify(**reply)

fmt: str = rv.get("format", "ssml")
text_format: TextFormats = TextFormats.SSML
if fmt in TextFormats._member_names_:
fmt: Optional[str] = rv.get("format")
if fmt == "ssml" or fmt is None:
text_format = TextFormats.SSML
# Only transcribe input if not SSML (transcribing messes up SSML)
transcribe = False
elif fmt == "text":
text_format = TextFormats.TEXT
transcribe = True
else:
return better_jsonify(**reply)

voice_id = icelandic_asciify(rv.get("voice_id", TTS_SETTINGS.DEFAULT_VOICE))
try:
Expand All @@ -586,7 +597,11 @@ def speech_api(version: int = 1) -> Response:
tts_options = TTSOptions(
voice=voice_id, speed=voice_speed, text_format=text_format
)
tts_output: TTSOutput = tts_to_file(text, tts_options=tts_options)
tts_output: TTSOutput = tts_to_file(
text,
tts_options=tts_options,
transcribe=transcribe,
)
url = tts_output.file.as_uri()
if url:
url = _audio_file_url_to_host_url(url, request)
Expand Down

0 comments on commit 04eb989

Please sign in to comment.