restructure the project and start using pytest
This commit is contained in:
10
multilang_translator/text_to_speech/piper_welcome.sh
Normal file
10
multilang_translator/text_to_speech/piper_welcome.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
SCRIPT_DIR=$(dirname "$(readlink -f "$BASH_SOURCE")")
|
||||
START_DIR=$(pwd)
|
||||
|
||||
cd $SCRIPT_DIR
|
||||
|
||||
echo 'Welcome to the world of speech synthesis!' | piper \
|
||||
--model en_US-lessac-medium \
|
||||
--output_file $SCRIPT_DIR/welcome.wav \
|
||||
|
||||
cd $START_DIR
|
||||
18
multilang_translator/text_to_speech/resample.py
Normal file
18
multilang_translator/text_to_speech/resample.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# resample .wave from 22.05 to 24kHz sampling rate
|
||||
|
||||
import librosa
|
||||
import soundfile as sf
|
||||
|
||||
|
||||
def resample(filename, out_filename, target_rate=int(24e3)):
|
||||
# Load the original audio file
|
||||
audio, rate = librosa.load(filename)
|
||||
|
||||
# Convert the sample rate to 24 kHz
|
||||
resampled_audio = librosa.resample(audio, orig_sr=rate, target_sr=target_rate)
|
||||
|
||||
# Save the resampled audio as a new .wav file
|
||||
sf.write(out_filename, resampled_audio, target_rate)
|
||||
|
||||
if __name__ == "__main__":
|
||||
resample('text_to_speech/welcome.wav', 'text_to_speech/welcome_resampled.wav')
|
||||
19
multilang_translator/text_to_speech/text_to_speech.py
Normal file
19
multilang_translator/text_to_speech/text_to_speech.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
import logging as log
|
||||
|
||||
TTS_DIR = os.path.join(os.path.dirname(__file__))
|
||||
|
||||
def synthesize(text, model="en_US-lessac-medium", output_file="out.wav"):
|
||||
|
||||
pwd = os.getcwd()
|
||||
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))
|
||||
os.chdir(pwd)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
synthesize("Hello, how are you?", "en_US-lessac-medium", "hello.wav")
|
||||
6353
multilang_translator/text_to_speech/voices.json
Normal file
6353
multilang_translator/text_to_speech/voices.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user