Update voice_of_the_doctor.py
Browse files- voice_of_the_doctor.py +12 -34
voice_of_the_doctor.py
CHANGED
|
@@ -1,35 +1,13 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
return output_filepath # Return file for frontend to play
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def text_to_speech_with_elevenlabs(input_text, output_filepath="doctor_voice.mp3"):
|
| 17 |
-
"""Generate voice using ElevenLabs (paid API)"""
|
| 18 |
-
if not ELEVENLABS_API_KEY:
|
| 19 |
-
raise ValueError("ELEVENLABS_API_KEY not set in environment variables")
|
| 20 |
-
|
| 21 |
-
client = ElevenLabs(api_key=ELEVENLABS_API_KEY)
|
| 22 |
-
|
| 23 |
-
# This returns a generator of audio chunks
|
| 24 |
-
audio_stream = client.text_to_speech.convert(
|
| 25 |
-
voice_id="EXAVITQu4vr4xnSDxMaL", # Example voice_id (replace with yours)
|
| 26 |
-
model_id="eleven_turbo_v2",
|
| 27 |
-
text=input_text
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
# Collect chunks into a file
|
| 31 |
-
with open(output_filepath, "wb") as f:
|
| 32 |
-
for chunk in audio_stream:
|
| 33 |
-
f.write(chunk)
|
| 34 |
-
|
| 35 |
return output_filepath
|
|
|
|
| 1 |
+
import soundfile as sf
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load Hugging Face TTS pipeline
|
| 5 |
+
pipe = pipeline("text-to-speech", model="maya-research/Veena")
|
| 6 |
+
|
| 7 |
+
def text_to_speech_with_veena(input_text, output_filepath="doctor_voice.wav"):
|
| 8 |
+
"""Generate speech using Hugging Face Veena TTS model"""
|
| 9 |
+
output = pipe(input_text)
|
| 10 |
+
audio_array = output["audio"]
|
| 11 |
+
sampling_rate = output["sampling_rate"]
|
| 12 |
+
sf.write(output_filepath, audio_array, sampling_rate)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return output_filepath
|