当我列出可用的语音api时,我刚刚开始使用Google的TTS api,将语音名称列为
我应该在下面的代码中写些什么来选择例如Standart-B语音?
texttospeech.types.VoiceSelectionParams(language_code ='tr-TR')
答案 0 :(得分:2)
这是C#的示例-您需要在VoiceSelectionParams
中指定语言代码和:
using Google.Cloud.TextToSpeech.V1;
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
var client = TextToSpeechClient.Create();
// List the voices, just for reference
foreach (var voice in client.ListVoices("tr-TR").Voices)
{
Console.WriteLine(voice.Name);
}
// Synthesize some speech
var input = new SynthesisInput { Text = "This is a demo of Google Cloud text to speech" };
// The language code is always required, even when it's sort of part of the name
var voiceSelection = new VoiceSelectionParams
{
LanguageCode = "tr-TR",
Name = "tr-TR-Standard-B"
};
var audioConfig = new AudioConfig { AudioEncoding = AudioEncoding.Mp3 };
var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);
File.WriteAllBytes("test.mp3", response.AudioContent.ToByteArray());
}
}
从文档来看,我认为在Python中是您想要的:
voice = texttospeech.types.VoiceSelectionParams(
language_code='tr-TR',
name='tr-TR-Standard-B')