Reputation: 21
I just started to use the Google's TTS api, when I list the available voices api lists the names of the voices as
What should I write to the code below to select for example Standart-B voice?
texttospeech.types.VoiceSelectionParams(language_code='tr-TR')
Upvotes: 2
Views: 1002
Reputation: 1500983
Here's an example in C# - you need to specify both the language code and the name in the 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());
}
}
Judging by the documentation, I think in Python you'd want:
voice = texttospeech.types.VoiceSelectionParams(
language_code='tr-TR',
name='tr-TR-Standard-B')
Upvotes: 3