-
Notifications
You must be signed in to change notification settings - Fork 1
/
pangpang.py
34 lines (29 loc) · 1006 Bytes
/
pangpang.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
import boto3
import time
from contextlib import closing
from pydub import AudioSegment
from pydub.playback import play
# Initialize polly client
polly_client = boto3.client('polly', "us-east-1")
while True:
# Text to be converted to speech
response = polly_client.synthesize_speech(VoiceId='Zhiyu',
OutputFormat='mp3',
Text = '胖胖吃一口饭, 喝一口死木西'
'')
# Save the audio to a file
if "AudioStream" in response:
with closing(response["AudioStream"]) as stream:
output = "OutputFilePath.mp3"
try:
# Open a file for writing the output as a binary stream
with open(output, "wb") as file:
file.write(stream.read())
except IOError as ioe:
print(ioe)
sys.exit(-1)
# Play the audio file
song = AudioSegment.from_mp3(output)
play(song)
# Delay for 30 seconds
time.sleep(30)