"""Synthesizes speech for multiple speakers.Make sure to be working in a virtual environment."""fromgoogle.cloudimporttexttospeech_v1beta1astexttospeech# Instantiates a clientclient=texttospeech.TextToSpeechClient()multi_speaker_markup=texttospeech.MultiSpeakerMarkup(turns=[texttospeech.MultiSpeakerMarkup.Turn(text="I've heard that the Google Cloud multi-speaker audio generation sounds amazing!",speaker="R",),texttospeech.MultiSpeakerMarkup.Turn(text="Oh? What's so good about it?",speaker="S"),texttospeech.MultiSpeakerMarkup.Turn(text="Well..",speaker="R"),texttospeech.MultiSpeakerMarkup.Turn(text="Well what?",speaker="S"),texttospeech.MultiSpeakerMarkup.Turn(text="Well, you should find it out by yourself!",speaker="R"),texttospeech.MultiSpeakerMarkup.Turn(text="Alright alright, let's try it out!",speaker="S"),])# Set the text input to be synthesizedsynthesis_input=texttospeech.SynthesisInput(multi_speaker_markup=multi_speaker_markup)# Build the voice request, select the language code ('en-US') and the voicevoice=texttospeech.VoiceSelectionParams(language_code="en-US",name="en-US-Studio-MultiSpeaker")# Select the type of audio file you want returnedaudio_config=texttospeech.AudioConfig(audio_encoding=texttospeech.AudioEncoding.MP3)# Perform the text-to-speech request on the text input with the selected# voice parameters and audio file typeresponse=client.synthesize_speech(input=synthesis_input,voice=voice,audio_config=audio_config)# The response's audio_content is binary.withopen("output.mp3","wb")asout:# Write the response to the output file.out.write(response.audio_content)print('Audio content written to file "output.mp3"')
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-12-05。"],[],[]]