-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateWav.py
43 lines (34 loc) · 1.15 KB
/
createWav.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
43
import boto3
import os
import wave
import argparse
import sys
polly = boto3.client('polly')
def createPolly (pollyText, fileName):
response = polly.synthesize_speech(
OutputFormat='pcm',
Text = pollyText,
SampleRate = '8000',
VoiceId = 'Joanna'
)
if "AudioStream" in response:
outputWav = '../../wav_files/' + fileName + '.wav'
with wave.open(outputWav, 'wb') as wav_file:
wav_file.setparams((1, 2, 8000, 0, 'NONE', 'NONE'))
wav_file.writeframes(response['AudioStream'].read())
return outputWav
parse_msg = 'Simple utility to create wav files for SMA via Polly'
parser = argparse.ArgumentParser(prog = 'createWav.py', description = parse_msg)
parser.add_argument('-file', help='Name of file to be created (without .wav)')
parser.add_argument('-text', help='Text of the audio to be created in quotes')
args = parser.parse_args()
fileName = args.file
pollyText = args.text
if not fileName:
print('Filename is rquired')
sys.exit()
if not pollyText:
print('Text is required')
sys.exit()
wavFile = createPolly(pollyText, fileName)
print('wav file created: ' + wavFile)