-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgTTS.py
32 lines (24 loc) · 989 Bytes
/
gTTS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "config/mamliKey.json"
def synthesize_text(text,gender):
"""Synthesizes speech from the input string of text."""
from google.cloud import texttospeech
client = texttospeech.TextToSpeechClient()
voice = "en-IN-Wavenet-" + gender
input_text = texttospeech.SynthesisInput(text=text)
# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices().
voice = texttospeech.VoiceSelectionParams(
language_code="en-IN",
name=voice,
)
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3,
speaking_rate=0.80,
)
response = client.synthesize_speech(
request={"input": input_text, "voice": voice, "audio_config": audio_config}
)
# The response's audio_content is binary.
with open("inputs/audio.wav", "wb") as out:
out.write(response.audio_content)