Add a simple text to speech example

This commit is contained in:
2024-12-14 14:39:38 +01:00
parent bb3b92972d
commit 74c2b8a34d
7 changed files with 34 additions and 4 deletions

4
.gitignore vendored
View File

@@ -1 +1,3 @@
*.pyc
*.pyc
venv/
text_to_speech/models

View File

@@ -29,9 +29,6 @@ def translator_de_fr(query):
return translate(MODEL, syspromts.TRANSLATOR_DE_FR + query)
if __name__ == "__main__":
response = translator_de_en(test_content.TESTSENTENCE_DE_BROKER)
print(json.dumps(response, indent=2))

0
main.py Normal file
View File

6
readme.md Normal file
View File

@@ -0,0 +1,6 @@
# Prerequisites
sudo apt install liblc3-tools
use python3.9
pip install piper-tts soundfile librosa

View File

@@ -0,0 +1,6 @@
SCRIPT_DIR=$(dirname "$(readlink -f "$BASH_SOURCE")")
echo 'Welcome to the world of speech synthesis!' | piper \
--model en_US-lessac-medium \
--output_file $SCRIPT_DIR/welcome.wav \
--download-dir $SCRIPT_DIR/models

View File

@@ -0,0 +1,19 @@
# resample .wave from 22.05 to 24kHz sampling rate
import librosa
import soundfile as sf
def resample():
# Load the original audio file
audio, rate = librosa.load('welcome.wav')
# Convert the sample rate to 24 kHz
resampled_rate = int(rate * 24 / 22050)
resampled_audio = librosa.resample(audio, rate, resampled_rate)
# Save the resampled audio as a new .wav file
sf.write('welcome_resampled.wav', resampled_audio, resampled_rate)
if __name__ == "__main__":
resample()

View File