-
Notifications
You must be signed in to change notification settings - Fork 1
/
tts.py
32 lines (23 loc) · 1.35 KB
/
tts.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
import azure.cognitiveservices.speech as speechsdk
import threading
import wave
import time
weatherfilename = 'output.wav'
pronunciation_assessment_config = speechsdk.PronunciationAssessmentConfig(json_string="{\"referenceText\":\"good morning\",\"gradingSystem\":\"HundredMark\",\"granularity\":\"Phoneme\",\"EnableMiscue\":true}")
speech_key = "YOUR_AZURE_SPEECH_STUDIO_KEY"
service_region = "eastus"
voice_name = 'en-US-JennyMultilingualNeural'
input_text = "Hi, this is Jenny Multilingual"
def text_to_speech(voice_name, input_text):
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
# Note: the voice setting will not overwrite the voice element in input SSML.
speech_config.speech_synthesis_voice_name = voice_name
text = input_text
# use the default speaker as audio output.
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
result = speech_synthesizer.speak_text_async(text).get()
if result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = result.cancellation_details
print("Speech synthesis canceled: {}".format(cancellation_details.reason))
if cancellation_details.reason == speechsdk.CancellationReason.Error:
print("Error details: {}".format(cancellation_details.error_details))