Google Cloud TTS语音选择

时间:2018-12-06 13:52:50

标签: google-cloud-platform google-text-to-speech

当我列出可用的语音api时,我刚刚开始使用Google的TTS api,将语音名称列为

  • tr-TR-Standart-A
  • tr-TR-Standart-B
  • ...

我应该在下面的代码中写些什么来选择例如Standart-B语音?

texttospeech.types.VoiceSelectionParams(language_code ='tr-TR')

1 个答案:

答案 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')