refractoring and more tests

This commit is contained in:
2024-12-19 14:01:32 +01:00
parent daa2d92257
commit 5d2f0f4fdf
10 changed files with 185 additions and 122 deletions

View File

@@ -2,6 +2,7 @@ import os
import subprocess
import time
import logging as log
import wave
TTS_DIR = os.path.join(os.path.dirname(__file__))
@@ -11,9 +12,15 @@ def synthesize(text, model="en_US-lessac-medium", output_file="out.wav"):
os.chdir(TTS_DIR)
start = time.time()
ret = subprocess.run(['piper', '--model', model, '--output_file', output_file], input=text.encode('utf-8'), check=True)
log.info("Running piper took %s s", round(time.time() - start, 3))
with wave.open(output_file, "rb") as wf:
frames = wf.getnframes()
rate = wf.getframerate()
length_in_seconds = round(frames / rate, 1)
log.info(f"Audio length: {length_in_seconds} s")
os.chdir(pwd)
log.info("Running piper took %s s", round(time.time() - start, 3))
if __name__ == "__main__":
synthesize("Hello, how are you?", "en_US-lessac-medium", "hello.wav")
return length_in_seconds