import time
from azure.cognitiveservices.speech import AudioDataStream, SpeechConfig, SpeechSynthesizer, SpeechSynthesisOutputFormat
from azure.cognitiveservices.speech.audio import AudioOutputConfig
import azure.cognitiveservices.speech as speechsdk

speech_key, service_region = "XXXXXXXXXXXXXXXXX", "BBBBBBBBBBBBBBBBBBBB"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_config.speech_synthesis_language = "en-US"
speech_config.speech_synthesis_voice_name = "en-US-AriaNeural"

# ####################################

# en-US-AIGenerate1Neural1 (Male)
# # en-US-AIGenerate2Neural1 (Female) 
# # en-US-AmberNeural (Female)
# # en-US-AnaNeural (Female, Child)
# # en-US-AriaNeural (Female)
# # en-US-AshleyNeural (Female)
# # en-US-BrandonNeural (Male)
# # en-US-ChristopherNeural (Male)
# # en-US-CoraNeural (Female)
# # en-US-DavisNeural (Male)
# # en-US-ElizabethNeural (Female)
# # en-US-EricNeural (Male)
# # en-US-GuyNeural (Male)
# # en-US-JacobNeural (Male)
# # en-US-JaneNeural (Female)
# # en-US-JasonNeural (Male)
# # en-US-JennyMultilingualNeural3 (Female)
# # en-US-JennyNeural (Female)
# # en-US-MichelleNeural (Female)
# # en-US-MonicaNeural (Female)
# # en-US-NancyNeural (Female)
# # en-US-RogerNeural1 (Male)
# # en-US-SaraNeural (Female)
# # en-US-SteffanNeural (Male)
# # en-US-TonyNeural (Male)
#


audio_config = AudioOutputConfig(use_default_speaker=True)
speech_synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

text_words = "It may have taken almost a year of bloodshed"
a="<speak version='1.0' xmlns='https://www.w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='en-US-AriaNeural'><prosody rate='slow'>"
b="</prosody></voice></speak>"

text_wor=a+text_words+b

result = speech_synthesizer.speak_ssml_async(text_wor).get()

# result = speech_synthesizer.speak_text_async(text_words).get()
if result.reason != speechsdk.ResultReason.SynthesizingAudioCompleted:
    print(result.reason)

with open("output"+str(time.time())+".mp3", "wb") as audio_file:
    audio_file.write(result.audio_data)

标签: none

添加新评论