Google Cloud TTS Voice выбор - PullRequest
0 голосов
/ 06 декабря 2018

Я только начал использовать API Google TTS, когда я перечисляю доступные голоса API, перечисляет имена голосов как

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

Что мне написать в приведенном ниже коде, чтобы выбрать, например, голос Standart-B?

texttospeech.types.VoiceSelectionParams (код_языка = 'тр-TR')

1 Ответ

0 голосов
/ 06 декабря 2018

Вот пример на 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')
...