Spaces:
Running
Running
Update text_speech_utils.py
Browse files- text_speech_utils.py +13 -2
text_speech_utils.py
CHANGED
@@ -37,8 +37,19 @@ def transcribe_audio(filename):
|
|
37 |
def save_text_as_audio(text, audio_filename):
|
38 |
print("Converting text to speech...")
|
39 |
tts = gTTS(text=text, lang='en', slow=False)
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# Function to play audio using pydub's playback
|
44 |
def play_audio(filename):
|
|
|
37 |
def save_text_as_audio(text, audio_filename):
|
38 |
print("Converting text to speech...")
|
39 |
tts = gTTS(text=text, lang='en', slow=False)
|
40 |
+
|
41 |
+
# Save as mp3 file
|
42 |
+
mp3_filename = audio_filename.replace('.wav', '.mp3')
|
43 |
+
tts.save(mp3_filename)
|
44 |
+
print(f"Audio saved as {mp3_filename}")
|
45 |
+
|
46 |
+
# Convert mp3 to wav using pydub
|
47 |
+
audio = AudioSegment.from_mp3(mp3_filename)
|
48 |
+
audio.export(audio_filename, format="wav")
|
49 |
+
|
50 |
+
# Delete the temporary mp3 file
|
51 |
+
os.remove(mp3_filename)
|
52 |
+
print(f"Audio converted and saved as {audio_filename}")
|
53 |
|
54 |
# Function to play audio using pydub's playback
|
55 |
def play_audio(filename):
|