Menampilkan daftar semua suara yang didukung

Anda bisa mendapatkan daftar lengkap semua suara yang didukung dengan memanggil endpoint voices:list dari API-nya. Anda juga dapat menemukan daftar lengkap suara yang tersedia di halaman Suara yang Didukung.

Cuplikan kode berikut menunjukkan cara mencantumkan suara yang tersedia di Text-to-Speech API untuk sintesis text-to-speech.

Contoh ini mengharuskan Anda menginstal dan melakukan inisialisasi Google Cloud CLI. Untuk mengetahui informasi tentang cara menyiapkan gcloud CLI, lihat Melakukan autentikasi ke TTS.

Protokol

Lihat endpoint voices:list API untuk mengetahui detail selengkapnya.

Untuk mendapatkan daftar suara yang tersedia untuk sintesis text-to-speech, buat permintaan GET ke endpoint voices:list API. Ganti PROJECT_ID dengan project ID Anda.

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \     -H "x-goog-user-project: PROJECT_ID" \     -H "Content-Type: application/json; charset=utf-8" \     "https://texttospeech.googleapis.com/v1/voices"

Text-to-Speech API menampilkan hasil berformat JSON yang terlihat mirip dengan berikut ini:

 {   "voices": [     {       "languageCodes": [         "es-ES"       ],       "name": "es-ES-Standard-A",       "ssmlGender": "FEMALE",       "naturalSampleRateHertz": 24000     },     {       "languageCodes": [         "ja-JP"       ],       "name": "ja-JP-Standard-A",       "ssmlGender": "FEMALE",       "naturalSampleRateHertz": 22050     },     {       "languageCodes": [         "pt-BR"       ],       "name": "pt-BR-Standard-A",       "ssmlGender": "FEMALE",       "naturalSampleRateHertz": 24000     },         ...   ] } 

Go

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Text-to-Speech, lihat library klien Text-to-Speech. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Text-to-Speech Go API.

Untuk mengautentikasi ke Text-to-Speech, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

 // ListVoices lists the available text to speech voices. func ListVoices(w io.Writer) error { 	ctx := context.Background()  	client, err := texttospeech.NewClient(ctx) 	if err != nil { 		return err 	} 	defer client.Close()  	// Performs the list voices request. 	resp, err := client.ListVoices(ctx, &texttospeechpb.ListVoicesRequest{}) 	if err != nil { 		return err 	}  	for _, voice := range resp.Voices { 		// Display the voice's name. Example: tpc-vocoded 		fmt.Fprintf(w, "Name: %v\n", voice.Name)  		// Display the supported language codes for this voice. Example: "en-US" 		for _, languageCode := range voice.LanguageCodes { 			fmt.Fprintf(w, "  Supported language: %v\n", languageCode) 		}  		// Display the SSML Voice Gender. 		fmt.Fprintf(w, "  SSML Voice Gender: %v\n", voice.SsmlGender.String())  		// Display the natural sample rate hertz for this voice. Example: 24000 		fmt.Fprintf(w, "  Natural Sample Rate Hertz: %v\n", 			voice.NaturalSampleRateHertz) 	}  	return nil } 

Java

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Text-to-Speech, lihat library klien Text-to-Speech. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Text-to-Speech Java API.

Untuk mengautentikasi ke Text-to-Speech, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

/**  * Demonstrates using the Text to Speech client to list the client's supported voices.  *  * @throws Exception on TextToSpeechClient Errors.  */ public static List<Voice> listAllSupportedVoices() throws Exception {   // Instantiates a client   try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {     // Builds the text to speech list voices request     ListVoicesRequest request = ListVoicesRequest.getDefaultInstance();      // Performs the list voices request     ListVoicesResponse response = textToSpeechClient.listVoices(request);     List<Voice> voices = response.getVoicesList();      for (Voice voice : voices) {       // Display the voice's name. Example: tpc-vocoded       System.out.format("Name: %s\n", voice.getName());        // Display the supported language codes for this voice. Example: "en-us"       List<ByteString> languageCodes = voice.getLanguageCodesList().asByteStringList();       for (ByteString languageCode : languageCodes) {         System.out.format("Supported Language: %s\n", languageCode.toStringUtf8());       }        // Display the SSML Voice Gender       System.out.format("SSML Voice Gender: %s\n", voice.getSsmlGender());        // Display the natural sample rate hertz for this voice. Example: 24000       System.out.format("Natural Sample Rate Hertz: %s\n\n", voice.getNaturalSampleRateHertz());     }     return voices;   } }

Node.js

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Text-to-Speech, lihat library klien Text-to-Speech. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Text-to-Speech Node.js API.

Untuk mengautentikasi ke Text-to-Speech, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

const textToSpeech = require('@google-cloud/text-to-speech');  const client = new textToSpeech.TextToSpeechClient();  const [result] = await client.listVoices({}); const voices = result.voices;  console.log('Voices:'); voices.forEach(voice => {   console.log(`Name: ${voice.name}`);   console.log(`  SSML Voice Gender: ${voice.ssmlGender}`);   console.log(`  Natural Sample Rate Hertz: ${voice.naturalSampleRateHertz}`);   console.log('  Supported languages:');   voice.languageCodes.forEach(languageCode => {     console.log(`    ${languageCode}`);   }); });

Python

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Text-to-Speech, lihat library klien Text-to-Speech. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Text-to-Speech Python API.

Untuk mengautentikasi ke Text-to-Speech, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

def list_voices():     """Lists the available voices."""     from google.cloud import texttospeech      client = texttospeech.TextToSpeechClient()      # Performs the list voices request     voices = client.list_voices()      for voice in voices.voices:         # Display the voice's name. Example: tpc-vocoded         print(f"Name: {voice.name}")          # Display the supported language codes for this voice. Example: "en-US"         for language_code in voice.language_codes:             print(f"Supported language: {language_code}")          ssml_gender = texttospeech.SsmlVoiceGender(voice.ssml_gender)          # Display the SSML Voice Gender         print(f"SSML Voice Gender: {ssml_gender.name}")          # Display the natural sample rate hertz for this voice. Example: 24000         print(f"Natural Sample Rate Hertz: {voice.natural_sample_rate_hertz}\n")  

Bahasa tambahan

C#: Ikuti Petunjuk penyiapan C# di halaman library klien, lalu kunjungi dokumentasi referensi Text-to-Speech untuk .NET.

PHP: Ikuti Petunjuk penyiapan PHP di halaman library klien, lalu kunjungi dokumentasi referensi Text-to-Speech untuk PHP.

Ruby: Ikuti Petunjuk penyiapan Ruby di halaman library klien, lalu kunjungi dokumentasi referensi Text-to-Speech untuk Ruby.