Skip to content

Commit

Permalink
ahotts
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Dec 14, 2024
1 parent 3f3f28a commit 93a2f5e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions build_raspOVOS_eu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ source /home/$USER/.venvs/ovos/bin/activate
echo "Setting up default wifi country..."
/usr/bin/raspi-config nonint do_wifi_country ES

echo "Installing AhoTTS"
git clone https://github.com/aholab/AhoTTS /tmp/AhoTTS
cd /tmp/AhoTTS
./script_compile_all_linux.sh
mv /tmp/AhoTTS/bin /usr/bin/AhoTTS/
cp /mounted-github-repo/packages/ahotts.py /usr/bin/AhoTTS/ahotts.py
cd ~

echo "Caching pre-trained padatious intents..."
mkdir -p /home/$USER/.local/share/mycroft/intent_cache
cp -rv /mounted-github-repo/intent_cache/eu-ES /home/$USER/.local/share/mycroft/intent_cache/
Expand Down
43 changes: 43 additions & 0 deletions packages/ahotts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import subprocess
import tempfile

import sys


def main(text_to_synthesize: str, output_file: str, speed: int = 100,
lang: str = "eu", tts_binary: str = "/usr/bin/AhoTTS/tts"):
print(f"Text to synthesize: {text_to_synthesize}")
print(f"Speed: {speed}")
print(f"TTS Binary: {tts_binary}")

# Use a temporary directory for intermediate files
with tempfile.TemporaryDirectory() as tmp_dir:
input_file = os.path.join(tmp_dir, "input.txt")
# Save the text to a temporary input file with WINDOWS-1252 encoding
with open(input_file, 'w', encoding='windows-1252') as txt_input:
txt_input.write(text_to_synthesize)

# Run TTS command
args = [tts_binary, f"-Speed={speed}", f"-Lang={lang}", f"-InputFile={input_file}",
f"-OutputFile={output_file}"]
exit_code = subprocess.call(args) # exit code 1 on success
if not os.path.isfile(output_file):
raise RuntimeError("TTS synth failed")

print(f"Saved: {output_file}")
return output_file


if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python ahotts.py <speed> <tts_binary_path> <text>")
sys.exit(1)

text = sys.argv[1]
outut_file = sys.argv[2]
try:
speed_arg = int(sys.argv[3]) # 25 - 300 - default 100
except:
speed_arg = 100
main(text, outut_file, speed_arg)

0 comments on commit 93a2f5e

Please sign in to comment.