-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo2.py
42 lines (30 loc) · 1.11 KB
/
demo2.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
31
32
33
34
35
36
37
38
39
40
41
42
import os
from google.cloud import texttospeech_v1
from google.cloud import texttospeech
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'sa_text_demo.json'
client = texttospeech_v1.TextToSpeechClient()
text = '''
Grok is an AI modeled after the Hitchhiker’s Guide to the Galaxy,
so intended to answer almost anything and, far harder,
even suggest what questions to ask!
Grok is designed to answer questions with a bit of wit and has a rebellious streak,
so please don’t use it if you hate humor!
'''
synthesis_input = texttospeech_v1.SynthesisInput(text = text)
# Configuring Voice
voice1 = texttospeech_v1.VoiceSelectionParams(
language_code='en-US',
ssml_gender=texttospeech_v1.SsmlVoiceGender.MALE
)
# try asian accents and nigerian accents
# Configuring output file
audio_config = texttospeech_v1.AudioConfig(
audio_encoding = texttospeech_v1.AudioEncoding.MP3
)
response = client.synthesize_speech(
input=synthesis_input,
voice=voice1,
audio_config=audio_config
)
with open('audio file.wav', 'wb') as output1:
output1.write(response.audio_content)