지원되는 모든 음성 나열

API의 voices:list 엔드포인트를 호출하면 지원되는 모든 음성의 전체 목록을 볼 수 있습니다. 또한 지원되는 음성 페이지에서 사용할 수 있는 음성의 전체 목록을 확인할 수 있습니다.

다음 코드 스니펫은 Cloud Text-to-Speech API에서 TTS(텍스트 음성 변환) 합성에 사용할 수 있는 음성을 나열하는 방법을 보여줍니다.

이 샘플에서는 gcloud를 설정하고 서비스 계정을 만들고 활성화해야 합니다. gcloud 설정, 서비스 계정 생성 및 활성화에 대한 자세한 내용은 빠른 시작: TTS(텍스트 음성 변환)를 참조하세요.

프로토콜

자세한 내용은 voices:list API 엔드포인트를 참조하세요.

TTS(텍스트 음성 변환) 합성에 사용 가능한 음성 목록을 보려면 voices:list API 엔드포인트에 GET 요청을 수행하세요.

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

Cloud Text-Speech API는 다음과 비슷한 JSON 형식의 결과를 반환합니다.

{
  "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
    },
        ...
  ]
}

C#

/// <summary>
/// Lists all the voices available for speech synthesis.
/// </summary>
/// <param name="desiredLanguageCode">Language code to filter on</param>
public static int ListVoices(string desiredLanguageCode = "")
{
    TextToSpeechClient client = TextToSpeechClient.Create();

    // Performs the list voices request
    var response = client.ListVoices(new ListVoicesRequest
    {
        LanguageCode = desiredLanguageCode
    });

    foreach (Voice voice in response.Voices)
    {
        // Display the voices's name.
        Console.WriteLine($"Name: {voice.Name}");

        // Display the supported language codes for this voice.
        foreach (var languageCode in voice.LanguageCodes)
        {
            Console.WriteLine($"Supported language(s): {languageCode}");
        }

        // Display the SSML Voice Gender
        Console.WriteLine("SSML Voice Gender: " +
            (SsmlVoiceGender)voice.SsmlGender);

        // Display the natural sample rate hertz for this voice.
        Console.WriteLine("Natural Sample Rate Hertz: " +
            voice.NaturalSampleRateHertz);
    }
    return 0;
}

Go

// 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
	}

	// 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
}

자바

/**
 * 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

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}`);
  });
});

PHP

use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;

function list_voices()
{
    // create client object
    $client = new TextToSpeechClient();

    // perform list voices request
    $response = $client->listVoices();
    $voices = $response->getVoices();

    foreach ($voices as $voice) {
        // display the voice's name. example: tpc-vocoded
        printf('Name: %s' . PHP_EOL, $voice->getName());

        // display the supported language codes for this voice. example: 'en-US'
        foreach ($voice->getLanguageCodes() as $languageCode) {
            printf('Supported language: %s' . PHP_EOL, $languageCode);
        }

        // SSML voice gender values from TextToSpeech\V1\SsmlVoiceGender
        $ssmlVoiceGender = ['SSML_VOICE_GENDER_UNSPECIFIED', 'MALE', 'FEMALE',
        'NEUTRAL'];

        // display the SSML voice gender
        $gender = $voice->getSsmlGender();
        printf('SSML voice gender: %s' . PHP_EOL, $ssmlVoiceGender[$gender]);

        // display the natural hertz rate for this voice
        printf('Natural Sample Rate Hertz: %d' . PHP_EOL,
            $voice->getNaturalSampleRateHertz());
    }

    $client->close();
}

Python

def list_voices():
    """Lists the available voices."""
    from google.cloud import texttospeech
    from google.cloud.texttospeech import enums
    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('Name: {}'.format(voice.name))

        # Display the supported language codes for this voice. Example: "en-US"
        for language_code in voice.language_codes:
            print('Supported language: {}'.format(language_code))

        ssml_gender = enums.SsmlVoiceGender(voice.ssml_gender)

        # Display the SSML Voice Gender
        print('SSML Voice Gender: {}'.format(ssml_gender.name))

        # Display the natural sample rate hertz for this voice. Example: 24000
        print('Natural Sample Rate Hertz: {}\n'.format(
            voice.natural_sample_rate_hertz))

Ruby

# Lists the available voices.
require "google/cloud/text_to_speech"

client = Google::Cloud::TextToSpeech.new

# Performs the list voices request
voices = client.list_voices.voices

voices.each do |voice|
  # Display the voice's name. Example: tpc-vocoded
  puts "Name: #{voice.name}"

  # Display the supported language codes for this voice. Example: "en-US"
  voice.language_codes.each do |language_code|
    puts "Supported language: #{language_code}"
  end

  # Display the SSML Voice Gender
  puts "SSML Voice Gender: #{voice.ssml_gender}"

  # Display the natural sample rate hertz for this voice. Example: 24000
  puts "Natural Sample Rate Hertz: #{voice.natural_sample_rate_hertz}\n"
end

이 페이지가 도움이 되었나요? 평가를 부탁드립니다.

다음에 대한 의견 보내기...

Cloud Text-to-Speech API
도움이 필요하시나요? 지원 페이지를 방문하세요.