IBM Cloud API Docs

Introduction

The IBM Watson™ Text to Speech service provides APIs that use IBM's speech-synthesis capabilities to synthesize text into natural-sounding speech in a variety of languages, dialects, and voices. The service supports at least one male or female voice, sometimes both, for each language. The audio is streamed back to the client with minimal delay.

For speech synthesis, the service supports a synchronous HTTP Representational State Transfer (REST) interface and a WebSocket interface. Both interfaces support plain text and SSML input. SSML is an XML-based markup language that provides text annotation for speech-synthesis applications. The WebSocket interface also supports the SSML <mark> element and word timings.

The service offers a customization interface that you can use to define sounds-like or phonetic translations for words. A sounds-like translation consists of one or more words that, when combined, sound like the word. A phonetic translation is based on the SSML phoneme format for representing a word. You can specify a phonetic translation in standard International Phonetic Alphabet (IPA) representation or in the proprietary IBM Symbolic Phonetic Representation (SPR).

The service also offers a Tune by Example feature that lets you define custom prompts. You can also define speaker models to improve the quality of your custom prompts. The service supports custom prompts only for US English custom models and voices.

This documentation describes Java SDK major version 9. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Node SDK major version 6. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Python SDK major version 5. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Ruby SDK major version 2. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes .NET Standard SDK major version 5. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Go SDK major version 2. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Swift SDK major version 4. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Unity SDK major version 5. For more information about how to update your code from the previous version, see the migration guide.

The IBM Watson Unity SDK has the following requirements.

  • The SDK requires Unity version 2018.2 or later to support Transport Layer Security (TLS) 1.2.
    • Set the project settings for both the Scripting Runtime Version and the Api Compatibility Level to .NET 4.x Equivalent.
    • For more information, see TLS 1.0 support.
  • The SDK doesn't support the WebGL projects. Change your build settings to any platform except WebGL.

For more information about how to install and configure the SDK and SDK Core, see https://github.com/watson-developer-cloud/unity-sdk.

The code examples on this tab use the client library that is provided for Java.

Maven

<dependency>
  <groupId>com.ibm.watson</groupId>
  <artifactId>ibm-watson</artifactId>
  <version>11.0.0</version>
</dependency>

Gradle

compile 'com.ibm.watson:ibm-watson:11.0.0'

GitHub

The code examples on this tab use the client library that is provided for Node.js.

Installation

npm install ibm-watson@^8.0.0

GitHub

The code examples on this tab use the client library that is provided for Python.

Installation

pip install --upgrade "ibm-watson>=7.0.0"

GitHub

The code examples on this tab use the client library that is provided for Ruby.

Installation

gem install ibm_watson

GitHub

The code examples on this tab use the client library that is provided for Go.

go get -u github.com/watson-developer-cloud/go-sdk/v2@v3.0.0

GitHub

The code examples on this tab use the client library that is provided for Swift.

Cocoapods

pod 'IBMWatsonTextToSpeechV1', '~> 5.0.0'

Carthage

github "watson-developer-cloud/swift-sdk" ~> 5.0.0

Swift Package Manager

.package(url: "https://github.com/watson-developer-cloud/swift-sdk", from: "5.0.0")

GitHub

The code examples on this tab use the client library that is provided for .NET Standard.

Package Manager

Install-Package IBM.Watson.TextToSpeech.v1 -Version 7.0.0

.NET CLI

dotnet add package IBM.Watson.TextToSpeech.v1 --version 7.0.0

PackageReference

<PackageReference Include="IBM.Watson.TextToSpeech.v1" Version="7.0.0" />

GitHub

The code examples on this tab use the client library that is provided for Unity.

GitHub

Endpoint URLs

Identify the base URL for your service instance.

IBM Cloud URLs

The base URLs come from the service instance. To find the URL, view the service credentials by clicking the name of the service in the Resource list. Use the value of the URL. Add the method to form the complete API endpoint for your request.

The following example URL represents a Text to Speech instance that is hosted in Washington DC:

https://api.us-east.text-to-speech.watson.cloud.ibm.com/instances/6bbda3b3-d572-45e1-8c54-22d6ed9e52c2

The following URLs represent the base URLs for Text to Speech. When you call the API, use the URL that corresponds to the location of your service instance.

  • Dallas: https://api.us-south.text-to-speech.watson.cloud.ibm.com
  • Washington DC: https://api.us-east.text-to-speech.watson.cloud.ibm.com
  • Frankfurt: https://api.eu-de.text-to-speech.watson.cloud.ibm.com
  • Sydney: https://api.au-syd.text-to-speech.watson.cloud.ibm.com
  • Tokyo: https://api.jp-tok.text-to-speech.watson.cloud.ibm.com
  • London: https://api.eu-gb.text-to-speech.watson.cloud.ibm.com
  • Seoul: https://api.kr-seo.text-to-speech.watson.cloud.ibm.com

Set the correct service URL by calling the setServiceUrl() method of the service instance.

Set the correct service URL by specifying the serviceUrl parameter when you create the service instance.

Set the correct service URL by calling the set_service_url() method of the service instance.

Set the correct service URL by specifying the service_url property of the service instance.

Set the correct service URL by calling the SetServiceURL() method of the service instance.

Set the correct service URL by setting the serviceURL property of the service instance.

Set the correct service URL by calling the SetServiceUrl() method of the service instance.

Set the correct service URL by calling the SetServiceUrl() method of the service instance.

Dallas API endpoint example for services managed on IBM Cloud

curl -X {request_method} -u "apikey:{apikey}" "https://api.us-south.text-to-speech.watson.cloud.ibm.com/instances/{instance_id}"

Your service instance might not use this URL

Default URL

https://api.us-south.text-to-speech.watson.cloud.ibm.com

Example for the Washington DC location

IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
TextToSpeech textToSpeech = new TextToSpeech(authenticator);
textToSpeech.setServiceUrl("https://api.us-east.text-to-speech.watson.cloud.ibm.com");

Default URL

https://api.us-south.text-to-speech.watson.cloud.ibm.com

Example for the Washington DC location

const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
const { IamAuthenticator } = require('ibm-watson/auth');

const textToSpeech = new TextToSpeechV1({
  authenticator: new IamAuthenticator({
    apikey: '{apikey}',
  }),
  serviceUrl: 'https://api.us-east.text-to-speech.watson.cloud.ibm.com',
});

Default URL

https://api.us-south.text-to-speech.watson.cloud.ibm.com

Example for the Washington DC location

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
text_to_speech = TextToSpeechV1(
    authenticator=authenticator
)

text_to_speech.set_service_url('https://api.us-east.text-to-speech.watson.cloud.ibm.com')

Default URL

https://api.us-south.text-to-speech.watson.cloud.ibm.com

Example for the Washington DC location

require "ibm_watson/authenticators"
require "ibm_watson/text_to_speech_v1"
include IBMWatson

authenticator = Authenticators::IamAuthenticator.new(
  apikey: "{apikey}"
)
text_to_speech = TextToSpeechV1.new(
  authenticator: authenticator
)
text_to_speech.service_url = "https://api.us-east.text-to-speech.watson.cloud.ibm.com"

Default URL

https://api.us-south.text-to-speech.watson.cloud.ibm.com

Example for the Washington DC location

textToSpeech, textToSpeechErr := texttospeechv1.NewTextToSpeechV1(options)

if textToSpeechErr != nil {
  panic(textToSpeechErr)
}

textToSpeech.SetServiceURL("https://api.us-east.text-to-speech.watson.cloud.ibm.com")

Default URL

https://api.us-south.text-to-speech.watson.cloud.ibm.com

Example for the Washington DC location

let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let textToSpeech = TextToSpeech(authenticator: authenticator)
textToSpeech.serviceURL = "https://api.us-east.text-to-speech.watson.cloud.ibm.com"

Default URL

https://api.us-south.text-to-speech.watson.cloud.ibm.com

Example for the Washington DC location

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("https://api.us-east.text-to-speech.watson.cloud.ibm.com");

Default URL

https://api.us-south.text-to-speech.watson.cloud.ibm.com

Example for the Washington DC location

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("https://api.us-east.text-to-speech.watson.cloud.ibm.com");

Cloud Pak for Data URLs

For services installed on Cloud Pak for Data, the base URLs come from both the cluster and service instance.

You can find the base URL from the Cloud Pak for Data web client in the details page about the instance. Click the name of the service in your list of instances to see the URL.

Use that URL in your requests to Text to Speech. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the URL by calling the setServiceUrl() method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by specifying the serviceUrl parameter when you create the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by specifying the url parameter when you create the service instance or by calling the set_url() method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by specifying the url parameter when you create the service instance or by calling the url= method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by specifying the URL parameter when you create the service instance or by calling the SetURL= method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by setting the serviceURL property of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by calling the SetEndpoint() method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by setting the Url property of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Endpoint example for Cloud Pak for Data

curl -X {request_method} -H "Authorization: Bearer {token}" "https://{cpd_cluster_host}{:port}/text-to-speech/{deployment_id}/instances/{instance_id}/api"

Endpoint example for Cloud Pak for Data

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}", "{username}", "{password}");
TextToSpeech textToSpeech = new TextToSpeech(authenticator);
textToSpeech.setServiceUrl("https://{cpd_cluster_host}{:port}/text-to-speech/{deployment_id}/instances/{instance_id}/api");

Endpoint example for Cloud Pak for Data

const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');

const textToSpeech = new TextToSpeechV1({
  authenticator: new CloudPakForDataAuthenticator({
    username: '{username}',
    password: '{password}',
    url: 'https://{cpd_cluster_host}{:port}',
  }),
  serviceUrl: 'https://{cpd_cluster_host}{:port}/text-to-speech/{deployment_id}/instances/{instance_id}/api',
});

Endpoint example for Cloud Pak for Data

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator

authenticator = CloudPakForDataAuthenticator(
    '{username}',
    '{password}',
    'https://{cpd_cluster_host}{:port}'
)

text_to_speech = TextToSpeechV1(
    authenticator=authenticator
)

text_to_speech.set_service_url('https://{cpd_cluster_host}{:port}/text-to-speech/{deployment_id}/instances/{instance_id}/api')

Endpoint example for Cloud Pak for Data

require "ibm_watson/authenticators"
require "ibm_watson/text_to_speech_v1"
include IBMWatson

authenticator = Authenticators::CLoudPakForDataAuthenticator.new(
  username: "{username}",
  password: "{password}",
  url: "https://{cpd_cluster_host}{:port}"
)
text_to_speech = TextToSpeechV1.new(
  authenticator: authenticator
)
text_to_speech.service_url = "https://{cpd_cluster_host}{:port}/text-to-speech/{deployment_id}/instances/{instance_id}/api"

Endpoint example for Cloud Pak for Data

textToSpeech, textToSpeechErr := texttospeechv1.NewTextToSpeechV1(options)

if textToSpeechErr != nil {
  panic(textToSpeechErr)
}

textToSpeech.SetServiceURL("https://{cpd_cluster_host}{:port}/text-to-speech/{deployment_id}/instances/{instance_id}/api")

Endpoint example for Cloud Pak for Data

let authenticator = CloudPakForDataAuthenticator(username: "{username}", password: "{password}", url: "https://{cpd_cluster_host}{:port}")
let textToSpeech = TextToSpeech(authenticator: authenticator)
textToSpeech.serviceURL = "https://{cpd_cluster_host}{:port}/text-to-speech/{deployment_id}/instances/{instance_id}/api"

Endpoint example for Cloud Pak for Data

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
    );

TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("https://{cpd_cluster_host}{:port}/text-to-speech/{deployment_id}/instances/{instance_id}/api");

Endpoint example for Cloud Pak for Data

var authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("https://{cpd_cluster_host}{:port}/text-to-speech/{deployment_id}/instances/{instance_id}/api");

Disabling SSL verification

All Watson services use Secure Sockets Layer (SSL) (or Transport Layer Security (TLS)) for secure connections between the client and server. The connection is verified against the local certificate store to ensure authentication, integrity, and confidentiality.

If you use a self-signed certificate, you need to disable SSL verification to make a successful connection.

Enabling SSL verification is highly recommended. Disabling SSL jeopardizes the security of the connection and data. Disable SSL only if necessary, and take steps to enable SSL as soon as possible.

To disable SSL verification for a curl request, use the --insecure (-k) option with the request.

To disable SSL verification, create an HttpConfigOptions object and set the disableSslVerification property to true. Then, pass the object to the service instance by using the configureClient method.

To disable SSL verification, set the disableSslVerification parameter to true when you create the service instance.

To disable SSL verification, specify True on the set_disable_ssl_verification method for the service instance.

To disable SSL verification, set the disable_ssl_verification parameter to true in the configure_http_client() method for the service instance.

To disable SSL verification, call the DisableSSLVerification method on the service instance.

To disable SSL verification, call the disableSSLVerification() method on the service instance. You cannot disable SSL verification on Linux.

To disable SSL verification, set the DisableSslVerification method to true on the service instance.

To disable SSL verification, set the DisableSslVerification method to true on the service instance.

Example to disable SSL verification with a service managed on IBM Cloud. Replace {apikey} and {url} with your service credentials.

curl -k -X {request_method} -u "apikey:{apikey}" "{url}/{method}"

Example to disable SSL verification with a service managed on IBM Cloud

IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
TextToSpeech textToSpeech = new TextToSpeech(authenticator);
textToSpeech.setServiceUrl("{url}");

HttpConfigOptions configOptions = new HttpConfigOptions.Builder()
  .disableSslVerification(true)
  .build();
textToSpeech.configureClient(configOptions);

Example to disable SSL verification with a service managed on IBM Cloud

const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
const { IamAuthenticator } = require('ibm-watson/auth');

const textToSpeech = new TextToSpeechV1({
  authenticator: new IamAuthenticator({
    apikey: '{apikey}',
  }),
  serviceUrl: '{url}',
  disableSslVerification: true,
});

Example to disable SSL verification with a service managed on IBM Cloud

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
text_to_speech = TextToSpeechV1(
    authenticator=authenticator
)

text_to_speech.set_service_url('{url}')

text_to_speech.set_disable_ssl_verification(True)

Example to disable SSL verification with a service managed on IBM Cloud

require "ibm_watson/authenticators"
require "ibm_watson/text_to_speech_v1"
include IBMWatson

authenticator = Authenticators::IamAuthenticator.new(
  apikey: "{apikey}"
)
text_to_speech = TextToSpeechV1.new(
  authenticator: authenticator
)
text_to_speech.service_url = "{url}"

text_to_speech.configure_http_client(disable_ssl_verification: true)

Example to disable SSL verification with a service managed on IBM Cloud

textToSpeech, textToSpeechErr := texttospeechv1.NewTextToSpeechV1(options)

if textToSpeechErr != nil {
  panic(textToSpeechErr)
}

textToSpeech.SetServiceURL("{url}")

textToSpeech.DisableSSLVerification()

Example to disable SSL verification with a service managed on IBM Cloud

let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let textToSpeech = TextToSpeech(authenticator: authenticator)
textToSpeech.serviceURL = "{url}"

textToSpeech.disableSSLVerification()

Example to disable SSL verification with a service managed on IBM Cloud

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

textToSpeech.DisableSslVerification(true);

Example to disable SSL verification with a service managed on IBM Cloud

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

textToSpeech.DisableSslVerification = true;

Example to disable SSL verification with an installed service

curl -k -X {request_method} -H "Authorization: Bearer {token}" "{url}/v1/{method}"

Example to disable SSL verification with an installed service

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}", "{username}", "{password}");
TextToSpeech textToSpeech = new TextToSpeech(authenticator);
textToSpeech.setServiceUrl("{url}";

HttpConfigOptions configOptions = new HttpConfigOptions.Builder()
  .disableSslVerification(true)
  .build();
textToSpeech.configureClient(configOptions);

Example to disable SSL verification with an installed service

const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');

const textToSpeech = new TextToSpeechV1({
  authenticator: new CloudPakForDataAuthenticator({
    username: '{username}',
    password: '{password}',
    url: 'https://{cpd_cluster_host}{:port}',
  }),
  serviceUrl: '{url}',
  disableSslVerification: true,
});

Example to disable SSL verification with an installed service

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator

authenticator = CloudPakForDataAuthenticator(
    '{username}',
    '{password}'
)

text_to_speech = TextToSpeechV1(
    authenticator=authenticator
)

text_to_speech.set_service_url('{url}')

text_to_speech.set_disable_ssl_verification(True)

Example to disable SSL verification with an installed service

require "ibm_watson/authenticators"
require "ibm_watson/text_to_speech_v1"
include IBMWatson

authenticator = Authenticators::CLoudPakForDataAuthenticator.new(
  username: "{username}",
  password: "{password}",
  url: "https://{cpd_cluster_host}{:port}"
)
text_to_speech = TextToSpeechV1.new(
  authenticator: authenticator
)
text_to_speech.service_url = "{url}"

text_to_speech.configure_http_client(disable_ssl_verification: true)

Example to disable SSL verification with an installed service

textToSpeech, textToSpeechErr := texttospeechv1.NewTextToSpeechV1(options)

if textToSpeechErr != nil {
  panic(textToSpeechErr)
}

textToSpeech.SetServiceURL("{url}")

textToSpeech.DisableSSLVerification()

Example to disable SSL verification with an installed service

let authenticator = WatsonCloudPakForDataAuthenticator(username: "{username}", password: "{password}", url: "https://{cpd_cluster_host}{:port}")
let textToSpeech = TextToSpeech(authenticator: authenticator)
textToSpeech.serviceURL = "{url}"

textToSpeech.disableSSLVerification()

Example to disable SSL verification with an installed service

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
    );

TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

textToSpeech.DisableSslVerification(true);

Example to disable SSL verification with an installed service

var authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

textToSpeech.DisableSslVerification = true;

Authentication

IBM Cloud services use IBM Cloud Identity and Access Management (IAM) to authenticate. With IBM Cloud Pak for Data, you pass a bearer token.

IBM Cloud

For IBM Cloud instances, you authenticate to the API by using IBM Cloud Identity and Access Management (IAM).

You can pass either a bearer token in an authorization header or an API key. Tokens support authenticated requests without embedding service credentials in every call. API keys use basic authentication. For more information, see Authenticating to Watson services.

  • For testing and development, you can pass an API key directly.
  • For production use, unless you use the Watson SDKs, use an IAM token.

If you pass in an API key, use apikey for the username and the value of the API key as the password. For example, if the API key is f5sAznhrKQyvBFFaZbtF60m5tzLbqWhyALQawBg5TjRI in the service credentials, include the credentials in your call like this:

curl -u "apikey:f5sAznhrKQyvBFFaZbtF60m5tzLbqWhyALQawBg5TjRI"

For IBM Cloud instances, the SDK provides initialization methods for each form of authentication.

  • Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
  • Use the access token to manage the lifecycle yourself. You must periodically refresh the token.

For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.

IBM Cloud. Replace {apikey} and {url} with your service credentials.

curl -X {request_method} -u "apikey:{apikey}" "{url}/v1/{method}"

IBM Cloud. SDK managing the IAM token. Replace {apikey} and {url}.

IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
TextToSpeech textToSpeech = new TextToSpeech(authenticator);
textToSpeech.setServiceUrl("{url}");

IBM Cloud. SDK managing the IAM token. Replace {apikey} and {url}.

const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
const { IamAuthenticator } = require('ibm-watson/auth');

const textToSpeech = new TextToSpeechV1({
  authenticator: new IamAuthenticator({
    apikey: '{apikey}',
  }),
  serviceUrl: '{url}',
});

IBM Cloud. SDK managing the IAM token. Replace {apikey} and {url}.

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
text_to_speech = TextToSpeechV1(
    authenticator=authenticator
)

text_to_speech.set_service_url('{url}')

IBM Cloud. SDK managing the IAM token. Replace {apikey} and {url}.

require "ibm_watson/authenticators"
require "ibm_watson/text_to_speech_v1"
include IBMWatson

authenticator = Authenticators::IamAuthenticator.new(
  apikey: "{apikey}"
)
text_to_speech = TextToSpeechV1.new(
  authenticator: authenticator
)
text_to_speech.service_url = "{url}"

IBM Cloud. SDK managing the IAM token. Replace {apikey} and {url}.

import (
  "github.com/IBM/go-sdk-core/core"
  "github.com/watson-developer-cloud/go-sdk/texttospeechv1"
)

func main() {
  authenticator := &core.IamAuthenticator{
    ApiKey: "{apikey}",
  }

  options := &texttospeechv1.TextToSpeechV1Options{
    Authenticator: authenticator,
  }

  textToSpeech, textToSpeechErr := texttospeechv1.NewTextToSpeechV1(options)

  if textToSpeechErr != nil {
    panic(textToSpeechErr)
  }

  textToSpeech.SetServiceURL("{url}")
}

IBM Cloud. SDK managing the IAM token. Replace {apikey} and {url}.

let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let textToSpeech = TextToSpeech(authenticator: authenticator)
textToSpeech.serviceURL = "{url}"

IBM Cloud. SDK managing the IAM token. Replace {apikey} and {url}.

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

IBM Cloud. SDK managing the IAM token. Replace {apikey} and {url}.

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

Cloud Pak for Data

For Cloud Pak for Data, you pass a bearer token in an Authorization header to authenticate to the API. The token is associated with a username.

  • For testing and development, you can use the bearer token that's displayed in the Cloud Pak for Data web client. To find this token, view the details for the service instance by clicking the name of the service in your list of instances. The details also include the service endpoint URL. Don't use this token in production because it does not expire.
  • For production use, create a user in the Cloud Pak for Data web client to use for authentication. Generate a token from that user's credentials with the POST /v1/authorize method.

For more information, see the Get authorization token method of the Cloud Pak for Data API reference.

For Cloud Pak for Data instances, pass either username and password credentials or a bearer token that you generate to authenticate to the API. Username and password credentials use basic authentication. However, the SDK manages the lifecycle of the token. Tokens are temporary security credentials. If you pass a token, you maintain the token lifecycle.

For production use, create a user in the Cloud Pak for Data web client to use for authentication, and decide which authentication mechanism to use.

  • To have the SDK manage the lifecycle of the token, use the username and password for that new user in your calls.
  • To manage the lifecycle of the token yourself, generate a token from that user's credentials. Call the POST /v1/authorize method to generate the token, and then pass the token in an Authorization header in your calls. You can see an example of the method on the Curl tab.

For more information, see the Get authorization token method of the Cloud Pak for Data API reference.

Don't use the bearer token that's displayed in the web client for the instance except during testing and development because that token does not expire.

To find your value for {url}, view the details for the service instance by clicking the name of the service in your list of instances in the Cloud Pak for Data web client.

Cloud Pak for Data. Generating a bearer token.

Replace {cpd_cluster_host} and {port} with the details for the service instance. Replace {username} and {password} with your Cloud Pak for Data credentials.

curl -k -X POST -H "cache-control: no-cache" -H "Content-Type: application/json" -d "{\"username\":\"{username}\",\"password\":\"{password}\"}" "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize"

The response includes a token property.

Authenticating to the API. Replace {token} with your details.

curl -H "Authorization: Bearer {token}" "{url}/v1/{method}"

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. For {url}, see Endpoint URLs.

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize", "{username}", "{password}");
TextToSpeech textToSpeech = new TextToSpeech(authenticator);
textToSpeech.setServiceUrl("{url}");

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. For {url}, see Endpoint URLs.

const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');

const textToSpeech = new TextToSpeechV1({
  authenticator: new CloudPakForDataAuthenticator({
    username: '{username}',
    password: '{password}',
    url: 'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize',
  }),
  serviceUrl: '{url}',
});

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. For {url}, see Endpoint URLs.

from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator

authenticator = CloudPakForDataAuthenticator(
    '{username}',
    '{password}',
    'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize'
)

text_to_speech = TextToSpeechV1(
    authenticator=authenticator
)

text_to_speech.set_service_url('{url}')

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. For {url}, see Endpoint URLs.

require "ibm_watson/authenticators"
require "ibm_watson/text_to_speech_v1"
include IBMWatson

authenticator = Authenticators::CloudPakForDataAuthenticator.new(
  username: "{username}",
  password: "{password}",
  url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize"
)
text_to_speech = TextToSpeechV1.new(
  authenticator: authenticator
)
text_to_speech.service_url = "{url}"

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. For {url}, see Endpoint URLs.

import (
  "github.com/IBM/go-sdk-core/core"
  "github.com/watson-developer-cloud/go-sdk/texttospeechv1"
)

func main() {
  authenticator := &core.CloudPakForDataAuthenticator{
    URL: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
    Username: "{username}",
    Password: "{password}",
  }

  options := &texttospeechv1.TextToSpeechV1Options{
    Authenticator: authenticator,
  }

  textToSpeech, textToSpeechErr := texttospeechv1.NewTextToSpeechV1(options)

  if textToSpeechErr != nil {
    panic(textToSpeechErr)
  }

  textToSpeech.SetServiceURL("{url}")
}

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. For {url}, see Endpoint URLs.

let authenticator = WatsonCloudPakForDataAuthenticator(username: "{username}", password: "{password}", url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize")
let textToSpeech = TextToSpeech(authenticator: authenticator)
textToSpeech.serviceURL = "{url}"

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. For {cpd_cluster_host}, {port}, {release}, and {instance_id}, see Endpoint URLs.

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
    username: "{username}",
    password: "{password}"
    );

TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. For {cpd_cluster_host}, {port}, {release}, and {instance_id}, see Endpoint URLs.

var authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
    username: "{username}",
    password: "{password}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

Access between services

Your application might use more than one Watson service. You can grant access between services and you can grant access to more than one service for your applications.

For IBM Cloud services, the method to grant access between Watson services varies depending on the type of API key. For more information, see IAM access.

  • To grant access between IBM Cloud services, create an authorization between the services. For more information, see Granting access between services.
  • To grant access to your services by applications without using user credentials, create a service ID, add an API key, and assign access policies. For more information, see Creating and working with service IDs.

When you give a user ID access to multiple services, use an endpoint URL that includes the service instance ID (for example, https://api.us-south.text-to-speech.watson.cloud.ibm.com/instances/6bbda3b3-d572-45e1-8c54-22d6ed9e52c2). You can find the instance ID in two places:

  • By clicking the service instance row in the Resource list. The instance ID is the GUID in the details pane.

  • By clicking the name of the service instance in the list and looking at the credentials URL.

    If you don't see the instance ID in the URL, the credentials predate service IDs. Add new credentials from the Service credentials page and use those credentials.

Because the Cloud Pak for Data bearer token is associated with a username, you can use the token for all CPD Watson services that are associated with the username.

Error handling

Text to Speech uses standard HTTP response codes to indicate whether a method completed successfully. HTTP response codes in the 2xx range indicate success. A response in the 4xx range is some sort of failure, and a response in the 5xx range usually indicates an internal system error that cannot be resolved by the user. Response codes are listed with the method.

ErrorResponse

Name Description
error
string
Description of the problem.
code
integer
HTTP response code.
code_description
string
Response message.
warnings
string
Warnings associated with the error.

The Java SDK generates an exception for any unsuccessful method invocation. All methods that accept an argument can also throw an IllegalArgumentException.

Exception Description
IllegalArgumentException An invalid argument was passed to the method.

When the Java SDK receives an error response from the Text to Speech service, it generates an exception from the com.ibm.watson.developer_cloud.service.exception package. All service exceptions contain the following fields.

Field Description
statusCode The HTTP response code that is returned.
message A message that describes the error.

When the Node SDK receives an error response from the Text to Speech service, it creates an Error object with information that describes the error that occurred. This error object is passed as the first parameter to the callback function for the method. The contents of the error object are as shown in the following table.

Error

Field Description
code The HTTP response code that is returned.
message A message that describes the error.

The Python SDK generates an exception for any unsuccessful method invocation. When the Python SDK receives an error response from the Text to Speech service, it generates an ApiException with the following fields.

Field Description
code The HTTP response code that is returned.
message A message that describes the error.
info A dictionary of additional information about the error.

When the Ruby SDK receives an error response from the Text to Speech service, it generates an ApiException with the following fields.

Field Description
code The HTTP response code that is returned.
message A message that describes the error.
info A dictionary of additional information about the error.

The Go SDK generates an error for any unsuccessful service instantiation and method invocation. You can check for the error immediately. The contents of the error object are as shown in the following table.

Error

Field Description
code The HTTP response code that is returned.
message A message that describes the error.

The Swift SDK returns a WatsonError in the completionHandler any unsuccessful method invocation. This error type is an enum that conforms to LocalizedError and contains an errorDescription property that returns an error message. Some of the WatsonError cases contain associated values that reveal more information about the error.

Field Description
errorDescription A message that describes the error.

When the .NET Standard SDK receives an error response from the Text to Speech service, it generates a ServiceResponseException with the following fields.

Field Description
Message A message that describes the error.
CodeDescription The HTTP response code that is returned.

When the Unity SDK receives an error response from the Text to Speech service, it generates an IBMError with the following fields.

Field Description
Url The URL that generated the error.
StatusCode The HTTP response code returned.
ErrorMessage A message that describes the error.
Response The contents of the response from the server.
ResponseHeaders A dictionary of headers returned by the request.

Example error handling

try {
  // Invoke a method
} catch (NotFoundException e) {
  // Handle Not Found (404) exception
} catch (RequestTooLargeException e) {
  // Handle Request Too Large (413) exception
} catch (ServiceResponseException e) {
  // Base class for all exceptions caused by error responses from the service
  System.out.println("Service returned status code "
    + e.getStatusCode() + ": " + e.getMessage());
}

Example error handling

textToSpeech.method(params)
  .catch(err => {
    console.log('error:', err);
  });

Example error handling

from ibm_watson import ApiException
try:
    # Invoke a method
except ApiException as ex:
    print "Method failed with status code " + str(ex.code) + ": " + ex.message

Example error handling

require "ibm_watson"
begin
  # Invoke a method
rescue IBMWatson::ApiException => ex
  print "Method failed with status code #{ex.code}: #{ex.error}"
end

Example error handling

import "github.com/watson-developer-cloud/go-sdk/texttospeechv1"

// Instantiate a service
textToSpeech, textToSpeechErr := texttospeechv1.NewTextToSpeechV1(options)

// Check for errors
if textToSpeechErr != nil {
  panic(textToSpeechErr)
}

// Call a method
result, _, responseErr := textToSpeech.MethodName(&methodOptions)

// Check for errors
if responseErr != nil {
  panic(responseErr)
}

Example error handling

textToSpeech.method() {
  response, error in

  if let error = error {
    switch error {
    case let .http(statusCode, message, metadata):
      switch statusCode {
      case .some(404):
        // Handle Not Found (404) exception
        print("Not found")
      case .some(413):
        // Handle Request Too Large (413) exception
        print("Payload too large")
      default:
        if let statusCode = statusCode {
          print("Error - code: \(statusCode), \(message ?? "")")
        }
      }
    default:
      print(error.localizedDescription)
    }
    return
  }

  guard let result = response?.result else {
    print(error?.localizedDescription ?? "unknown error")
    return
  }

  print(result)
}

Example error handling

try
{
    // Invoke a method
}
catch(ServiceResponseException e)
{
    Console.WriteLine("Error: " + e.Message);
}
catch (Exception e)
{
    Console.WriteLine("Error: " + e.Message);
}

Example error handling

// Invoke a method
textToSpeech.MethodName(Callback, Parameters);

// Check for errors
private void Callback(DetailedResponse<ExampleResponse> response, IBMError error)
{
    if (error == null)
    {
        Log.Debug("ExampleCallback", "Response received: {0}", response.Response);
    }
    else
    {
        Log.Debug("ExampleCallback", "Error received: {0}, {1}, {3}", error.StatusCode, error.ErrorMessage, error.Response);
    }
}

Data handling

Additional headers

Some Watson services accept special parameters in headers that are passed with the request.

You can pass request header parameters in all requests or in a single request to the service.

To pass a request header, use the --header (-H) option with a curl request.

To pass header parameters with every request, use the setDefaultHeaders method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, use the addHeader method as a modifier on the request before you execute it.

To pass header parameters with every request, specify the headers parameter when you create the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, use the headers method as a modifier on the request before you execute it.

To pass header parameters with every request, specify the set_default_headers method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, include headers as a dict in the request.

To pass header parameters with every request, specify the add_default_headers method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, specify the headers method as a chainable method in the request.

To pass header parameters with every request, specify the SetDefaultHeaders method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, specify the Headers as a map in the request.

To pass header parameters with every request, add them to the defaultHeaders property of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, pass the headers parameter to the request method.

To pass header parameters in a single request, use the WithHeader() method as a modifier on the request before you execute it. See Data collection for an example use of this method.

To pass header parameters in a single request, use the WithHeader() method as a modifier on the request before you execute it.

Example header parameter in a request

curl -X {request_method} -H "Request-Header: {header_value}" "{url}/v1/{method}"

Example header parameter in a request

ReturnType returnValue = textToSpeech.methodName(parameters)
  .addHeader("Custom-Header", "{header_value}")
  .execute();

Example header parameter in a request

const parameters = {
  {parameters}
};

textToSpeech.methodName(
  parameters,
  headers: {
    'Custom-Header': '{header_value}'
  })
   .then(result => {
    console.log(response);
  })
  .catch(err => {
    console.log('error:', err);
  });

Example header parameter in a request

response = text_to_speech.methodName(
    parameters,
    headers = {
        'Custom-Header': '{header_value}'
    })

Example header parameter in a request

response = text_to_speech.headers(
  "Custom-Header" => "{header_value}"
).methodName(parameters)

Example header parameter in a request

result, _, responseErr := textToSpeech.MethodName(
  &methodOptions{
    Headers: map[string]string{
      "Accept": "application/json",
    },
  },
)

Example header parameter in a request

let customHeader: [String: String] = ["Custom-Header": "{header_value}"]
textToSpeech.methodName(parameters, headers: customHeader) {
  response, error in
}

Example header parameter in a request for a service managed on IBM Cloud

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

textToSpeech.WithHeader("Custom-Header", "header_value");

Example header parameter in a request for an installed service

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
    );

TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("https://{cpd_cluster_host}{:port}/text-to-speech/{release}/instances/{instance_id}/api");

textToSpeech.WithHeader("Custom-Header", "header_value");

Example header parameter in a request for a service managed on IBM Cloud

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

textToSpeech.WithHeader("Custom-Header", "header_value");

Example header parameter in a request for an installed service

var authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("https://{cpd_cluster_host}{:port}/text-to-speech/{release}/instances/{instance_id}/api");

textToSpeech.WithHeader("Custom-Header", "header_value");

Response details

The Text to Speech service might return information to the application in response headers.

To access all response headers that the service returns, include the --include (-i) option with a curl request. To see detailed response data for the request, including request headers, response headers, and extra debugging information, include the --verbose (-v) option with the request.

Example request to access response headers

curl -X {request_method} {authentication_method} --include "{url}/v1/{method}"

To access information in the response headers, use one of the request methods that returns details with the response: executeWithDetails(), enqueueWithDetails(), or rxWithDetails(). These methods return a Response<T> object, where T is the expected response model. Use the getResult() method to access the response object for the method, and use the getHeaders() method to access information in response headers.

Example request to access response headers

Response<ReturnType> response = textToSpeech.methodName(parameters)
  .executeWithDetails();
// Access response from methodName
ReturnType returnValue = response.getResult();
// Access information in response headers
Headers responseHeaders = response.getHeaders();

All response data is available in the Response<T> object that is returned by each method. To access information in the response object, use the following properties.

Property Description
result Returns the response for the service-specific method.
headers Returns the response header information.
status Returns the HTTP status code.

Example request to access response headers

textToSpeech.methodName(parameters)
  .then(response => {
    console.log(response.headers);
  })
  .catch(err => {
    console.log('error:', err);
  });

The return value from all service methods is a DetailedResponse object. To access information in the result object or response headers, use the following methods.

DetailedResponse

Method Description
get_result() Returns the response for the service-specific method.
get_headers() Returns the response header information.
get_status_code() Returns the HTTP status code.

Example request to access response headers

text_to_speech.set_detailed_response(True)
response = text_to_speech.methodName(parameters)
# Access response from methodName
print(json.dumps(response.get_result(), indent=2))
# Access information in response headers
print(response.get_headers())
# Access HTTP response status
print(response.get_status_code())

The return value from all service methods is a DetailedResponse object. To access information in the response object, use the following properties.

DetailedResponse

Property Description
result Returns the response for the service-specific method.
headers Returns the response header information.
status Returns the HTTP status code.

Example request to access response headers

response = text_to_speech.methodName(parameters)
# Access response from methodName
print response.result
# Access information in response headers
print response.headers
# Access HTTP response status
print response.status

The return value from all service methods is a DetailedResponse object. To access information in the response object or response headers, use the following methods.

DetailedResponse

Method Description
GetResult() Returns the response for the service-specific method.
GetHeaders() Returns the response header information.
GetStatusCode() Returns the HTTP status code.

Example request to access response headers

import (
  "github.com/IBM/go-sdk-core/core"
  "github.com/watson-developer-cloud/go-sdk/texttospeechv1"
)
result, response, responseErr := textToSpeech.MethodName(
  &methodOptions{})
// Access result
core.PrettyPrint(response.GetResult(), "Result ")

// Access response headers
core.PrettyPrint(response.GetHeaders(), "Headers ")

// Access status code
core.PrettyPrint(response.GetStatusCode(), "Status Code ")

All response data is available in the WatsonResponse<T> object that is returned in each method's completionHandler.

Example request to access response headers

textToSpeech.methodName(parameters) {
  response, error in

  guard let result = response?.result else {
    print(error?.localizedDescription ?? "unknown error")
    return
  }
  print(result) // The data returned by the service
  print(response?.statusCode)
  print(response?.headers)
}

The response contains fields for response headers, response JSON, and the status code.

DetailedResponse

Property Description
Result Returns the result for the service-specific method.
Response Returns the raw JSON response for the service-specific method.
Headers Returns the response header information.
StatusCode Returns the HTTP status code.

Example request to access response headers

var results = textToSpeech.MethodName(parameters);

var result = results.Result;            //  The result object
var responseHeaders = results.Headers;  //  The response headers
var responseJson = results.Response;    //  The raw response JSON
var statusCode = results.StatusCode;    //  The response status code

The response contains fields for response headers, response JSON, and the status code.

DetailedResponse

Property Description
Result Returns the result for the service-specific method.
Response Returns the raw JSON response for the service-specific method.
Headers Returns the response header information.
StatusCode Returns the HTTP status code.

Example request to access response headers

private void Example()
{
    textToSpeech.MethodName(Callback, Parameters);
}

private void Callback(DetailedResponse<ResponseType> response, IBMError error)
{
    var result = response.Result;                 //  The result object
    var responseHeaders = response.Headers;       //  The response headers
    var responseJson = reresponsesults.Response;  //  The raw response JSON
    var statusCode = response.StatusCode;         //  The response status code
}

Data labels (IBM Cloud)

You can remove data associated with a specific customer if you label the data with a customer ID when you send a request to the service.

  • Use the X-Watson-Metadata header to associate a customer ID with the data. By adding a customer ID to a request, you indicate that it contains data that belongs to that customer.

    Specify a random or generic string for the customer ID. Do not include personal data, such as an email address. Pass the string customer_id={id} as the argument of the header.

    Labeling data is used only by methods that accept customer data.

  • Use the Delete labeled data method to remove data that is associated with a customer ID.

Use this process of labeling and deleting data only when you want to remove the data that is associated with a single customer, not when you want to remove data for multiple customers. For more information about Text to Speech and labeling data, see Information security.

For more information about how to pass headers, see Additional headers.

Data collection (IBM Cloud)

By default, Text to Speech service instances managed on IBM Cloud that are not part of Premium plans collect data about API requests and their results. This data is collected only to improve the services for future users. The collected data is not shared or made public. Data is not collected for services that are part of Premium plans.

To prevent IBM usage of your data for an API request, set the X-Watson-Learning-Opt-Out header parameter to true. You can also disable request logging at the account level. For more information, see Controlling request logging for Watson services.

You must set the header on each request that you do not want IBM to access for general service improvements.

You can set the header by using the setDefaultHeaders method of the service object.

You can set the header by using the headers parameter when you create the service object.

You can set the header by using the set_default_headers method of the service object.

You can set the header by using the add_default_headers method of the service object.

You can set the header by using the SetDefaultHeaders method of the service object.

You can set the header by adding it to the defaultHeaders property of the service object.

You can set the header by using the WithHeader() method of the service object.

Example request with a service managed on IBM Cloud

curl -u "apikey:{apikey}" -H "X-Watson-Learning-Opt-Out: true" "{url}/{method}"

Example request with a service managed on IBM Cloud

Map<String, String> headers = new HashMap<String, String>();
headers.put("X-Watson-Learning-Opt-Out", "true");

textToSpeech.setDefaultHeaders(headers);

Example request with a service managed on IBM Cloud

const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
const { IamAuthenticator } = require('ibm-watson/auth');

const textToSpeech = new TextToSpeechV1({
  authenticator: new IamAuthenticator({
    apikey: '{apikey}',
  }),
  serviceUrl: '{url}',
  headers: {
    'X-Watson-Learning-Opt-Out': 'true'
  }
});

Example request with a service managed on IBM Cloud

text_to_speech.set_default_headers({'x-watson-learning-opt-out': "true"})

Example request with a service managed on IBM Cloud

text_to_speech.add_default_headers(headers: {"x-watson-learning-opt-out" => "true"})

Example request with a service managed on IBM Cloud

import "net/http"

headers := http.Header{}
headers.Add("x-watson-learning-opt-out", "true")
textToSpeech.SetDefaultHeaders(headers)

Example request with a service managed on IBM Cloud

textToSpeech.defaultHeaders["X-Watson-Learning-Opt-Out"] = "true"

Example request with a service managed on IBM Cloud

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

textToSpeech.WithHeader("X-Watson-Learning-Opt-Out", "true");

Example request with a service managed on IBM Cloud

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var textToSpeech = new TextToSpeechService(authenticator);
textToSpeech.SetServiceUrl("{url}");

textToSpeech.WithHeader("X-Watson-Learning-Opt-Out", "true");

Synchronous and asynchronous requests

The Java SDK supports both synchronous (blocking) and asynchronous (non-blocking) execution of service methods. All service methods implement the ServiceCall interface.

  • To call a method synchronously, use the execute method of the ServiceCall interface. You can call the execute method directly from an instance of the service.
  • To call a method asynchronously, use the enqueue method of the ServiceCall interface to receive a callback when the response arrives. The ServiceCallback interface of the method's argument provides onResponse and onFailure methods that you override to handle the callback.

The Ruby SDK supports both synchronous (blocking) and asynchronous (non-blocking) execution of service methods. All service methods implement the Concurrent::Async module. When you use the synchronous or asynchronous methods, an IVar object is returned. You access the DetailedResponse object by calling ivar_object.value.

For more information about the Ivar object, see the IVar class docs.

  • To call a method synchronously, either call the method directly or use the .await chainable method of the Concurrent::Async module.

    Calling a method directly (without .await) returns a DetailedResponse object.

  • To call a method asynchronously, use the .async chainable method of the Concurrent::Async module.

You can call the .await and .async methods directly from an instance of the service.

Example synchronous request

ReturnType returnValue = textToSpeech.method(parameters).execute();

Example asynchronous request

textToSpeech.method(parameters).enqueue(new ServiceCallback<ReturnType>() {
  @Override public void onResponse(ReturnType response) {
    . . .
  }
  @Override public void onFailure(Exception e) {
    . . .
  }
});

Example synchronous request

response = text_to_speech.method_name(parameters)

or

response = text_to_speech.await.method_name(parameters)

Example asynchronous request

response = text_to_speech.async.method_name(parameters)

WebSockets

Synthesize audio (WebSockets)

Synthesizes text to spoken audio over a WebSocket connection. The synthesize method establishes a connection with the service. You then send the text to be synthesized to the service as a JSON text message over the connection. The service returns the audio as a stream of binary data.

The endpoint for the WebSocket API is

wss://api.{location}.text-to-speech.watson.cloud.ibm.com/instances/{instance_id}/v1/synthesize
  • {location} indicates where your application is hosted:

  • {instance_id} indicates the unique identifier of the service instance. For more information how to find the instance ID, see Access between services.

The examples in the documentation abbreviate wss://api.{location}.text-to-speech.watson.cloud.ibm.com/instances/{instance_id} to {ws_url}. So all WebSocket examples call the method as {ws_url}/v1/synthesize.

You can provide a maximum of 5 KB of either plain text or text that is annotated with SSML. With most voices, you can use the SSML <mark> element to request the location of the marker in the audio stream, and you can request word timing information in the form of start and end times for all strings of the input text. The service returns mark and word timing results as text messages over the connection. The <mark> element and word timings are available only with the WebSocket interface, not with the HTTP interface.

See also:

The WebSocket interface cannot be called from curl. Use a client-side scripting language to call the interface. The example request uses JavaScript to invoke the WebSocket synthesize method.

Audio formats (accept types)

The service can return audio in the following formats (MIME types).

  • Where indicated, you can optionally specify the sampling rate (rate) of the audio. You must specify a sampling rate for the audio/alaw, audio/l16, and audio/mulaw formats. A specified sampling rate must lie in the range of 8 kHz to 192 kHz. Some formats restrict the sampling rate to certain values, as noted.
  • For the audio/l16 format, you can optionally specify the endianness (endianness) of the audio: endianness=big-endian or endianness=little-endian.

Use the accept parameter to specify the requested format of the response audio. Specify */* with the parameter to use the default, Ogg format with the Opus codec (audio/ogg;codecs=opus). The service always returns single-channel audio.

  • audio/alaw - You must specify the rate of the audio.
  • audio/basic - The service returns audio with a sampling rate of 8000 Hz.
  • audio/flac - You can optionally specify the rate of the audio. The default sampling rate is 22,050 Hz.
  • audio/l16 - You must specify the rate of the audio. You can optionally specify the endianness of the audio. The default endianness is little-endian.
  • audio/mp3 - You can optionally specify the rate of the audio. The default sampling rate is 22,050 Hz.
  • audio/mpeg - You can optionally specify the rate of the audio. The default sampling rate is 22,050 Hz.
  • audio/mulaw - You must specify the rate of the audio.
  • audio/ogg - The service returns the audio in the vorbis codec. You can optionally specify the rate of the audio. The default sampling rate is 22,050 Hz.
  • audio/ogg;codecs=opus - You can optionally specify the rate of the audio. Only the following values are valid sampling rates: 48000, 24000, 16000, 12000, or 8000. If you specify a different value, the service returns an error. The default sampling rate is 48,000 Hz.
  • audio/ogg;codecs=vorbis - You can optionally specify the rate of the audio. The default sampling rate is 22,050 Hz.
  • audio/wav - You can optionally specify the rate of the audio. The default sampling rate is 22,050 Hz.
  • audio/webm - The service returns the audio in the opus codec. The service returns audio with a sampling rate of 48,000 Hz.
  • audio/webm;codecs=opus - The service returns audio with a sampling rate of 48,000 Hz.
  • audio/webm;codecs=vorbis - You can optionally specify the rate of the audio. The default sampling rate is 22,050 Hz.
  • */* - Specifies the default audio format: audio/ogg;codecs=opus.

Note: By default, the service returns audio in the Ogg audio format with the Opus codec (audio/ogg;codecs=opus). However, the Ogg audio format is not supported with the Safari browser. If you are using the service with the Safari browser, you must use the accept parameter specify a different format in which you want the service to return the audio.

For more information about specifying an audio format, including additional details about some of the formats, see Using audio formats.

URI /v1/synthesize

Request

The client establishes a connection with the service by using the WebSocket constructor to create an instance of a WebSocket connection object. The constructor sets the following basic parameters for the connection and the synthesis.

Parameters of synthesize method

  • Pass a valid access token to authenticate with the service. You must use the access token before it expires.

    • IBM Cloud only. Pass an Identity and Access Management (IAM) access token to authenticate with the service. You pass an IAM access token instead of passing an API key with the call. For more information, see Authenticating to IBM Cloud.

    • IBM Cloud Pak for Data only. Pass an access token as you would with the Authorization header of an HTTP request. For more information, see Authenticating to IBM Cloud Pak for Data.

  • The voice to use for speech synthesis. The default voice is en-US_MichaelV3Voice. For Text to Speech for IBM Cloud Pak for Data, if you do not install the en-US_MichaelV3Voice, you must either specify a voice with the request or specify a new default voice for your installation of the service.

    See also:

    Allowable values: [de-DE_BirgitV3Voice, de-DE_DieterV3Voice, de-DE_ErikaV3Voice, en-AU_HeidiExpressive, en-AU_JackExpressive, en-GB_CharlotteV3Voice, en-GB_JamesV3Voice, en-GB_KateV3Voice, en-US_AllisonExpressive, en-US_AllisonV3Voice, en-US_EmilyV3Voice, en-US_EmmaExpressive, en-US_HenryV3Voice, en-US_KevinV3Voice, en-US_LisaExpresssive, en-US_LisaV3Voice, en-US_MichaelExpressive, en-US_MichaelV3Voice, en-US_OliviaV3Voice, es-ES_LauraV3Voice, es-ES_EnriqueV3Voice es-LA_SofiaV3Voice, es-US_SofiaV3Voice, fr-CA_LouiseV3Voice, fr-FR_NicolasV3Voice, fr-FR_ReneeV3Voice, it-IT_FrancescaV3Voice, ja-JP_EmiV3Voice, ko-KR_JinV3Voice, ko-KR_SiWooVoice, nl-NL_MerelV3Voice, pt-BR_IsabelaV3Voice]

    Default: en-US_MichaelV3Voice

  • The customization ID (GUID) of a custom model that is to be used for the synthesis. A custom model works only if it matches the language of the indicated voice. You must make the request with credentials for the instance of the service that owns the custom model. Omit the parameter to use the specified voice with no customization.

  • Indicates whether IBM can use data that is sent over the connection to improve the service for future users. Specify true to prevent IBM from accessing the logged data. See Data collection.

    Default: false

  • Associates a customer ID with all data that is passed over the connection. The parameter accepts the argument customer_id={id}, where {id} is a random or generic string that is to be associated with the data. URL-encode the argument to the parameter, for example customer_id%3dmy_ID. By default, no customer ID is associated with the data. See Data labels.

  • For German voices, indicates how the service is to spell out strings of individual letters. To indicate the pace of the spelling, specify one of the following values:

    • default - The service reads the characters at the rate at which it synthesizes speech for the request. You can also omit the parameter entirely to achieve the default behavior.

    • singles - The service reads the characters one at a time, with a brief pause between each character.

    • pairs - The service reads the characters two at a time, with a brief pause between each pair.

    • triples - The service reads the characters three at a time, with a brief pause between each triplet.

    The parameter is beta functionality.

    See also: Specifying how strings are spelled out.

    Allowable values: [default, singles, pairs, triples]

    Default: default

  • The percentage change from the default speaking rate of the voice that is used for speech synthesis. Each voice has a default speaking rate that is optimized to represent a normal rate of speech. The parameter accepts an integer that represents the percentage change from the voice's default rate:

    • Specify a signed negative integer to reduce the speaking rate by that percentage. For example, -10 reduces the rate by ten percent.

    • Specify an unsigned or signed positive integer to increase the speaking rate by that percentage. For example, 10 and +10 increase the rate by ten percent.

    • Specify 0 or omit the parameter to get the default speaking rate for the voice.

    The parameter affects the rate for an entire request. It is beta functionality.

    See also: Modifying the speaking rate.

    Default: 0

  • The percentage change from the default speaking pitch of the voice that is used for speech synthesis. Each voice has a default speaking pitch that is optimized to represent a normal tone of voice. The parameter accepts an integer that represents the percentage change from the voice's default tone:

    • Specify a signed negative integer to lower the voice's pitch by that percentage. For example, -5 reduces the tone by five percent.

    • Specify an unsigned or signed positive integer to increase the voice's pitch by that percentage. For example, 5 and +5 increase the tone by five percent.

    • Specify 0 or omit the parameter to get the default speaking pitch for the voice.

    The parameter affects the pitch for an entire request. It is beta functionality.

    See also: Modifying the speaking pitch.

    Default: 0

The client initiates the synthesis by sending a JSON-formatted text message to the service over the connection.

Parameters of WebSocket text messages

  • The text that us to be synthesized. Provide plain text or text that is annotated with SSML. SSML input can include the SSML <mark> element. Pass a maximum of 5 KB of text. For more information, see

  • The requested format (MIME type) of the audio. Specify */* to use the default, Ogg format with the Opus codec (audio/ogg;codecs=opus). For more information about specifying an audio format, see Audio formats (accept types) in the method description.

    Allowable values: [audio/alaw, audio/basic, audio/flac, audio/l16, audio/mp3, audio/mpeg, audio/mulaw, audio/ogg, audio/ogg;codecs=opus, audio/ogg;codecs=vorbis, audio/wav, audio/webm, audio/webm;codecs=opus, audio/webm;codecs=vorbis, */*]

  • An array that specifies whether the service is to return word timing information for all strings of the input text. Specify words as the element of the array to request word timing information. The service returns the start and end time of each word of the input. Specify an empty array or omit the parameter to receive no word timing information.

    Not supported for Japanese input text.

Response

Returns the binary audio stream for the input text as an array of bytes in the specified audio format (MIME type).

If the input text includes one or more SSML <mark> elements, the service returns one or more text messages that include one or more Marks objects.

Marks

  • The location of one or more marks in the audio stream. The response includes one or more marks arrays, each with one more arrays as its elements. Each inner array has two elements: the name of the mark (a string) and the time in seconds at which the mark occurs in the audio (a float). For more information, see Specifying an SSML mark.

    An example response for a single mark named here follows:

    {"marks": [
      ["here", 0.501]
    ] }

If the request includes the timings parameter to request word timing information, the service returns one or more text messages that include one or more Timings objects.

Timings

  • Word timing information for strings in the audio stream. The response includes one or more words arrays, each with one of more arrays as its elements. Each inner array consists of three elements: a word from the input text (a string) followed by the start and end time in seconds at which the word occurs in the audio (two floats). For more information, see Requesting word timings for all words.

    An example response for a single word follows:

    {"words": [
      ["Hello", 0.069, 0.165]
    ] }

Response handling

Response handling for the WebSocket interface is different from HTTP response handling. The WebSocket constructor returns an instance of a WebSocket connection object. You assign application-specific calls to the following methods of the object to handle events that are associated with the connection. Each event handler must accept a single argument for an event from the connection. The event that it accepts causes it to execute.

Methods

  • The status of the connection's opening.

  • Response messages from the service, including the results of the synthesis as a binary stream.

  • Errors for the connection or request.
  • The status of the connection's closing.

The connection can produce the following return codes.

Return code

  • The connection closed normally.

  • The connection closed due to a protocol error.

  • The connection closed abnormally.

  • The connection closed because the frame size exceeded the 4 MB limit.

  • The service is terminating the connection because it encountered an unexpected condition that prevents it from fulfilling the request, such as an invalid argument. The return code can also indicate that the input text was too large. The text cannot exceed 5 KB.

If any errors or warnings are associated with the connection, the service sends a JSON response as a text message with one of the following fields.

Connection response

  • An error message that describes the problem. The message is followed by a second message that includes the boolean value true to indicate that the connection is closed, the return code for the error, and a brief message. The connection is closed.

  • Warning messages about invalid or unknown parameters that are included with the request. The warning includes a descriptive message and a list of invalid argument strings. For example, "Unknown arguments: {invalid_arg_1}, {invalid_arg_2}." The connection remains open.

Example request

var access_token = '{access_token}';
var wsURI = '{ws_url}/v1/synthesize'
  + '?access_token=' + access_token
  + '&voice=en-US_AllisonV3Voice';

function onOpen(evt) {
  var message = {
    text: 'Hello world',
    accept: 'audio/ogg;codecs=opus'
  };
  // The service currently accepts a single message per WebSocket connection.
  websocket.send(JSON.stringify(message));
}

var audioParts = [];
var finalAudio;

function onMessage(evt) {
  if (typeof evt.data === 'string') {
    console.log('Received string message: ', evt.data)
  } else {
    console.log('Received ' + evt.data.size + ' binary bytes', evt.data.type);
    audioParts.push(evt.data);
  }
}

function onClose(evt) {
  console.log('WebSocket closed', evt.code, evt.reason);
  finalAudio = new Blob(audioParts, {type: format});
  console.log('final audio: ', finalAudio);
}

function onError(evt) {
  console.log('WebSocket error', evt);
}

var websocket = new WebSocket(wsURI);
websocket.onopen = onOpen;
websocket.onclose = onClose;
websocket.onmessage = onMessage;
websocket.onerror = onError;

Methods

List voices

Lists all voices available for use with the service. The information includes the name, language, gender, and other details about the voice. The ordering of the list of voices can change from call to call; do not rely on an alphabetized or static list of voices. To see information about a specific voice, use the Get a voice.

See also: Listing all voices

Lists all voices available for use with the service. The information includes the name, language, gender, and other details about the voice. The ordering of the list of voices can change from call to call; do not rely on an alphabetized or static list of voices. To see information about a specific voice, use the Get a voice.

See also: Listing all voices.

Lists all voices available for use with the service. The information includes the name, language, gender, and other details about the voice. The ordering of the list of voices can change from call to call; do not rely on an alphabetized or static list of voices. To see information about a specific voice, use the Get a voice.

See also: Listing all voices.

Lists all voices available for use with the service. The information includes the name, language, gender, and other details about the voice. The ordering of the list of voices can change from call to call; do not rely on an alphabetized or static list of voices. To see information about a specific voice, use the Get a voice.

See also: Listing all voices.

Lists all voices available for use with the service. The information includes the name, language, gender, and other details about the voice. The ordering of the list of voices can change from call to call; do not rely on an alphabetized or static list of voices. To see information about a specific voice, use the Get a voice.

See also: Listing all voices.

GET /v1/voices
ListVoices()
ServiceCall<Voices> listVoices()
listVoices(params)
list_voices(
        self,
        **kwargs,
    ) -> DetailedResponse

Request

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

  • curl -X GET -u "apikey:{apikey}" "{url}/v1/voices"
  • curl -X GET --header "Authorization: Bearer {token}" "{url}/v1/voices"
  • IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}"
        );
    
    TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
    textToSpeech.SetServiceUrl("{url}");
    
    var result = textToSpeech.ListVoices();
    
    Console.WriteLine(result.Result);
  • CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
        url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
        username: "{username}",
        password: "{password}"
        );
    
    TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
    textToSpeech.SetServiceUrl("{url}");
    
    var result = textToSpeech.ListVoices();
    
    Console.WriteLine(result.Result);
  • IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
    TextToSpeech textToSpeech = new TextToSpeech(authenticator);
    textToSpeech.setServiceUrl("{url}");
    
    Voices voices = textToSpeech.listVoices().execute().getResult();
    System.out.println(voices);
  • CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize", "{username}", "{password}");
    TextToSpeech textToSpeech = new TextToSpeech(authenticator);
    textToSpeech.setServiceUrl("{url}");
    
    Voices voices = textToSpeech.listVoices().execute().getResult();
    System.out.println(voices);
  • const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
    const { IamAuthenticator } = require('ibm-watson/auth');
    
    const textToSpeech = new TextToSpeechV1({
      authenticator: new IamAuthenticator({
        apikey: '{apikey}',
      }),
      serviceUrl: '{url}',
    });
    
    textToSpeech.listVoices()
      .then(voices => {
        console.log(JSON.stringify(voices, null, 2));
      })
      .catch(err => {
        console.log('error:', err);
      });
  • const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
    const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');
    
    const textToSpeech = new TextToSpeechV1({
      authenticator: new CloudPakForDataAuthenticator({
        username: '{username}',
        password: '{password}',
        url: 'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize',
      }),
      serviceUrl: '{url}',
    });
    
    textToSpeech.listVoices()
      .then(voices => {
        console.log(JSON.stringify(voices, null, 2));
      })
      .catch(err => {
        console.log('error:', err);
      });
  • import json
    from ibm_watson import TextToSpeechV1
    from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
    
    authenticator = IAMAuthenticator('{apikey}')
    text_to_speech = TextToSpeechV1(
        authenticator=authenticator
    )
    
    text_to_speech.set_service_url('{url}')
    
    voices = text_to_speech.list_voices().get_result()
    print(json.dumps(voices, indent=2))
  • import json
    from ibm_watson import TextToSpeechV1
    from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator
    
    authenticator = CloudPakForDataAuthenticator(
        '{username}',
        '{password}',
        'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize'
    )
    
    text_to_speech = TextToSpeechV1(
        authenticator=authenticator
    )
    
    text_to_speech.set_service_url('{url}')
    
    voices = text_to_speech.list_voices().get_result()
    print(json.dumps(voices, indent=2))

Response

Information about all available voices.

Information about all available voices.

Information about all available voices.

Information about all available voices.

Information about all available voices.

Status Code

  • OK. The request succeeded.

  • Not Acceptable. The request specified an Accept header with an incompatible content type.

  • Unsupported Media Type. The request specified an unacceptable media type.

  • Internal Server Error. The service experienced an internal error.

  • Service Unavailable. The service is currently unavailable.

Example responses
  • {
      "voices": [
        {
          "name": "es-LA_SofiaV3Voice",
          "language": "es-LA",
          "customizable": true,
          "gender": "female",
          "url": "{url}/v1/voices/es-LA_SofiaV3Voice",
          "supported_features": {
            "voice_transformation": false,
            "custom_pronunciation": true
          },
          "description": "Sofia: Latin American Spanish (español latinoamericano) female voice."
        },
        {
          "name": "pt-BR_IsabelaV3Voice",
          "language": "pt-BR",
          "customizable": true,
          "gender": "female",
          "url": "{url}/v1/voices/pt-BR_IsabelaV3Voice",
          "supported_features": {
            "voice_transformation": false,
            "custom_pronunciation": true
          },
          "description": "Isabela: Brazilian Portuguese (portuguĂŞs brasileiro) female voice."
        },
        {
          "name": "en-GB_KateV3Voice",
          "language": "en-GB",
          "customizable": true,
          "gender": "female",
          "url": "{url}/v1/voices/en-GB_KateV3Voice",
          "supported_features": {
            "voice_transformation": false,
            "custom_pronunciation": true
          },
          "description": "Kate: British English female voice."
        }
      ]
    }
  • {
      "voices": [
        {
          "name": "es-LA_SofiaV3Voice",
          "language": "es-LA",
          "customizable": true,
          "gender": "female",
          "url": "{url}/v1/voices/es-LA_SofiaV3Voice",
          "supported_features": {
            "voice_transformation": false,
            "custom_pronunciation": true
          },
          "description": "Sofia: Latin American Spanish (español latinoamericano) female voice."
        },
        {
          "name": "pt-BR_IsabelaV3Voice",
          "language": "pt-BR",
          "customizable": true,
          "gender": "female",
          "url": "{url}/v1/voices/pt-BR_IsabelaV3Voice",
          "supported_features": {
            "voice_transformation": false,
            "custom_pronunciation": true
          },
          "description": "Isabela: Brazilian Portuguese (portuguĂŞs brasileiro) female voice."
        },
        {
          "name": "en-GB_KateV3Voice",
          "language": "en-GB",
          "customizable": true,
          "gender": "female",
          "url": "{url}/v1/voices/en-GB_KateV3Voice",
          "supported_features": {
            "voice_transformation": false,
            "custom_pronunciation": true
          },
          "description": "Kate: British English female voice."
        }
      ]
    }

Get a voice

Gets information about the specified voice. The information includes the name, language, gender, and other details about the voice. Specify a customization ID to obtain information for a custom model that is defined for the language of the specified voice. To list information about all available voices, use the List voices method.

See also: Listing a specific voice.

Gets information about the specified voice. The information includes the name, language, gender, and other details about the voice. Specify a customization ID to obtain information for a custom model that is defined for the language of the specified voice. To list information about all available voices, use the List voices method.

See also: Listing a specific voice.

Gets information about the specified voice. The information includes the name, language, gender, and other details about the voice. Specify a customization ID to obtain information for a custom model that is defined for the language of the specified voice. To list information about all available voices, use the List voices method.

See also: Listing a specific voice.

Gets information about the specified voice. The information includes the name, language, gender, and other details about the voice. Specify a customization ID to obtain information for a custom model that is defined for the language of the specified voice. To list information about all available voices, use the List voices method.

See also: Listing a specific voice.

Gets information about the specified voice. The information includes the name, language, gender, and other details about the voice. Specify a customization ID to obtain information for a custom model that is defined for the language of the specified voice. To list information about all available voices, use the List voices method.

See also: Listing a specific voice.

GET /v1/voices/{voice}
GetVoice(string voice, string customizationId = null)
ServiceCall<Voice> getVoice(GetVoiceOptions getVoiceOptions)
getVoice(params)
get_voice(
        self,
        voice: str,
        *,
        customization_id: str = None,
        **kwargs,
    ) -> DetailedResponse

Request

Use the GetVoiceOptions.Builder to create a GetVoiceOptions object that contains the parameter values for the getVoice method.

Path Parameters

  • The voice for which information is to be returned.

    Allowable values: [de-DE_BirgitV3Voice,de-DE_DieterV3Voice,de-DE_ErikaV3Voice,en-AU_HeidiExpressive,en-AU_JackExpressive,en-GB_CharlotteV3Voice,en-GB_JamesV3Voice,en-GB_KateV3Voice,en-US_AllisonExpressive,en-US_AllisonV3Voice,en-US_EmilyV3Voice,en-US_EmmaExpressive,en-US_HenryV3Voice,en-US_KevinV3Voice,en-US_LisaExpressive,en-US_LisaV3Voice,en-US_MichaelExpressive,en-US_MichaelV3Voice,en-US_OliviaV3Voice,es-ES_EnriqueV3Voice,es-ES_LauraV3Voice,es-LA_SofiaV3Voice,es-US_SofiaV3Voice,fr-CA_LouiseV3Voice,fr-FR_NicolasV3Voice,fr-FR_ReneeV3Voice,it-IT_FrancescaV3Voice,ja-JP_EmiV3Voice,ko-KR_JinV3Voice,nl-NL_MerelV3Voice,pt-BR_IsabelaV3Voice]

Query Parameters

  • The customization ID (GUID) of a custom model for which information is to be returned. You must make the request with credentials for the instance of the service that owns the custom model. Omit the parameter to see information about the specified voice with no customization.

parameters

  • The voice for which information is to be returned.

    Allowable values: [de-DE_BirgitV3Voice,de-DE_DieterV3Voice,de-DE_ErikaV3Voice,en-AU_HeidiExpressive,en-AU_JackExpressive,en-GB_CharlotteV3Voice,en-GB_JamesV3Voice,en-GB_KateV3Voice,en-US_AllisonExpressive,en-US_AllisonV3Voice,en-US_EmilyV3Voice,en-US_EmmaExpressive,en-US_HenryV3Voice,en-US_KevinV3Voice,en-US_LisaExpressive,en-US_LisaV3Voice,en-US_MichaelExpressive,en-US_MichaelV3Voice,en-US_OliviaV3Voice,es-ES_EnriqueV3Voice,es-ES_LauraV3Voice,es-LA_SofiaV3Voice,es-US_SofiaV3Voice,fr-CA_LouiseV3Voice,fr-FR_NicolasV3Voice,fr-FR_ReneeV3Voice,it-IT_FrancescaV3Voice,ja-JP_EmiV3Voice,ko-KR_JinV3Voice,nl-NL_MerelV3Voice,pt-BR_IsabelaV3Voice]

  • The customization ID (GUID) of a custom model for which information is to be returned. You must make the request with credentials for the instance of the service that owns the custom model. Omit the parameter to see information about the specified voice with no customization.

The getVoice options.

parameters

  • The voice for which information is to be returned.

    Allowable values: [de-DE_BirgitV3Voice,de-DE_DieterV3Voice,de-DE_ErikaV3Voice,en-AU_HeidiExpressive,en-AU_JackExpressive,en-GB_CharlotteV3Voice,en-GB_JamesV3Voice,en-GB_KateV3Voice,en-US_AllisonExpressive,en-US_AllisonV3Voice,en-US_EmilyV3Voice,en-US_EmmaExpressive,en-US_HenryV3Voice,en-US_KevinV3Voice,en-US_LisaExpressive,en-US_LisaV3Voice,en-US_MichaelExpressive,en-US_MichaelV3Voice,en-US_OliviaV3Voice,es-ES_EnriqueV3Voice,es-ES_LauraV3Voice,es-LA_SofiaV3Voice,es-US_SofiaV3Voice,fr-CA_LouiseV3Voice,fr-FR_NicolasV3Voice,fr-FR_ReneeV3Voice,it-IT_FrancescaV3Voice,ja-JP_EmiV3Voice,ko-KR_JinV3Voice,nl-NL_MerelV3Voice,pt-BR_IsabelaV3Voice]

  • The customization ID (GUID) of a custom model for which information is to be returned. You must make the request with credentials for the instance of the service that owns the custom model. Omit the parameter to see information about the specified voice with no customization.

parameters

  • The voice for which information is to be returned.

    Allowable values: [de-DE_BirgitV3Voice,de-DE_DieterV3Voice,de-DE_ErikaV3Voice,en-AU_HeidiExpressive,en-AU_JackExpressive,en-GB_CharlotteV3Voice,en-GB_JamesV3Voice,en-GB_KateV3Voice,en-US_AllisonExpressive,en-US_AllisonV3Voice,en-US_EmilyV3Voice,en-US_EmmaExpressive,en-US_HenryV3Voice,en-US_KevinV3Voice,en-US_LisaExpressive,en-US_LisaV3Voice,en-US_MichaelExpressive,en-US_MichaelV3Voice,en-US_OliviaV3Voice,es-ES_EnriqueV3Voice,es-ES_LauraV3Voice,es-LA_SofiaV3Voice,es-US_SofiaV3Voice,fr-CA_LouiseV3Voice,fr-FR_NicolasV3Voice,fr-FR_ReneeV3Voice,it-IT_FrancescaV3Voice,ja-JP_EmiV3Voice,ko-KR_JinV3Voice,nl-NL_MerelV3Voice,pt-BR_IsabelaV3Voice]

  • The customization ID (GUID) of a custom model for which information is to be returned. You must make the request with credentials for the instance of the service that owns the custom model. Omit the parameter to see information about the specified voice with no customization.

  • curl -X GET -u "apikey:{apikey}" "{url}/v1/voices/en-US_AllisonV3Voice"
  • curl -X GET --header "Authorization: Bearer {token}" "{url}/v1/voices/en-US_AllisonV3Voice"
  • IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}"
        );
    
    TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
    textToSpeech.SetServiceUrl("{url}");
    
    var result = textToSpeech.GetVoice("en-US_AllisonV3Voice");
    
    Console.WriteLine(result.Result);
  • CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
        url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
        username: "{username}",
        password: "{password}"
        );
    
    TextToSpeechService textToSpeech = new TextToSpeechService(authenticator);
    textToSpeech.SetServiceUrl("{url}");
    
    var result = textToSpeech.GetVoice("en-US_AllisonV3Voice");
    
    Console.WriteLine(result.Result);
  • IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
    TextToSpeech textToSpeech = new TextToSpeech(authenticator);
    textToSpeech.setServiceUrl("{url}");
    
    GetVoiceOptions getVoiceOptions = new GetVoiceOptions.Builder()
      .voice("en-US_AllisonV3Voice")
      .build();
    
    Voice voice = textToSpeech.getVoice(getVoiceOptions).execute().getResult();
    System.out.println(voice);
  • CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize", "{username}", "{password}");
    TextToSpeech textToSpeech = new TextToSpeech(authenticator);
    textToSpeech.setServiceUrl("{url}");
    
    GetVoiceOptions getVoiceOptions = new GetVoiceOptions.Builder()
      .voice("en-US_AllisonV3Voice")
      .build();
    
    Voice voice = textToSpeech.getVoice(getVoiceOptions).execute().getResult();
    System.out.println(voice);
  • const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
    const { IamAuthenticator } = require('ibm-watson/auth');
    
    const textToSpeech = new TextToSpeechV1({
      authenticator: new IamAuthenticator({
        apikey: '{apikey}',
      }),
      serviceUrl: '{url}',
    });
    
    const getVoiceParams = {
      voice: 'en-US_AllisonV3Voice',
    };
    
    textToSpeech.getVoice(getVoiceParams)
      .then(voice => {
        console.log(JSON.stringify(voice, null, 2));
      })
      .catch(err => {
        console.log('error:', err);
      });
  • const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
    const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');
    
    const textToSpeech = new TextToSpeechV1({
      authenticator: new CloudPakForDataAuthenticator({
        username: '{username}',
        password: '{password}',
        url: 'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize',
      }),
      serviceUrl: '{url}',
    });
    
    const getVoiceParams = {
      voice: 'en-US_AllisonV3Voice',
    };
    
    textToSpeech.getVoice(getVoiceParams)
      .then(voice => {
        console.log(JSON.stringify(voice, null, 2));
      })
      .catch(err => {
        console.log('error:', err);
      });
  • import json
    from ibm_watson import TextToSpeechV1
    from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
    
    authenticator = IAMAuthenticator('{apikey}')
    text_to_speech = TextToSpeechV1(
        authenticator=authenticator
    )
    
    text_to_speech.set_service_url('{url}')
    
    voice = text_to_speech.get_voice('en-US_AllisonV3Voice').get_result()
    print(json.dumps(voice, indent=2))
  • import json
    from ibm_watson import TextToSpeechV1
    from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator
    
    authenticator = CloudPakForDataAuthenticator(
        '{username}',
        '{password}',
        'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize'
    )
    
    text_to_speech = TextToSpeechV1(
        authenticator=authenticator
    )
    
    text_to_speech.set_service_url('{url}')
    
    voice = text_to_speech.get_voice('en-US_AllisonV3Voice').get_result()
    print(json.dumps(voice, indent=2))

Response

Information about an available voice.

Information about an available voice.

Information about an available voice.

Information about an available voice.