Skip to content

Commit

Permalink
Fix for local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfiero committed May 3, 2024
1 parent e056e94 commit 4ecb84d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions software/source/server/services/tts/piper/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, config):
self.piper_directory = ""
self.install(config["service_directory"])

def tts(self, text):
def tts(self, text, mobile):
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
output_file = temp_file.name
piper_dir = self.piper_directory
Expand All @@ -34,10 +34,16 @@ def tts(self, text):
)

# TODO: hack to format audio correctly for device
outfile = tempfile.gettempdir() + "/" + "raw.dat"
ffmpeg.input(temp_file.name).output(
outfile, f="s16le", ar="16000", ac="1", loglevel="panic"
).run()
if mobile:
outfile = tempfile.gettempdir() + "/" + "output.wav"
ffmpeg.input(temp_file.name).output(
outfile, f="wav", ar="16000", ac="1", loglevel="panic"
).run()
else:
outfile = tempfile.gettempdir() + "/" + "raw.dat"
ffmpeg.input(temp_file.name).output(
outfile, f="s16le", ar="16000", ac="1", loglevel="panic"
).run()

return outfile

Expand Down

0 comments on commit 4ecb84d

Please sign in to comment.