Spaces:
Runtime error
Runtime error
ayureasehealthcare
commited on
Create tts.py
Browse files- utils/tts.py +18 -0
utils/tts.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from google.cloud import texttospeech
|
2 |
+
|
3 |
+
def text_to_speech(text, language_code="en-IN"):
|
4 |
+
client = texttospeech.TextToSpeechClient()
|
5 |
+
input_text = texttospeech.SynthesisInput(text=text)
|
6 |
+
|
7 |
+
voice = texttospeech.VoiceSelectionParams(
|
8 |
+
language_code=language_code,
|
9 |
+
ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL
|
10 |
+
)
|
11 |
+
audio_config = texttospeech.AudioConfig(audio_encoding=texttospeech.AudioEncoding.LINEAR16)
|
12 |
+
|
13 |
+
response = client.synthesize_speech(input=input_text, voice=voice, audio_config=audio_config)
|
14 |
+
audio_path = "response_audio.wav"
|
15 |
+
with open(audio_path, "wb") as out:
|
16 |
+
out.write(response.audio_content)
|
17 |
+
return audio_path
|
18 |
+
|