use of com.ibm.watson.text_to_speech.v1.model.Prompts in project java-sdk by watson-developer-cloud.
the class TextToSpeech method createSpeakerModel.
/**
* Create a speaker model.
*
* <p>Creates a new speaker model, which is an optional enrollment token for users who are to add
* prompts to custom models. A speaker model contains information about a user's voice. The
* service extracts this information from a WAV audio sample that you pass as the body of the
* request. Associating a speaker model with a prompt is optional, but the information that is
* extracted from the speaker model helps the service learn about the speaker's voice.
*
* <p>A speaker model can make an appreciable difference in the quality of prompts, especially
* short prompts with relatively little audio, that are associated with that speaker. A speaker
* model can help the service produce a prompt with more confidence; the lack of a speaker model
* can potentially compromise the quality of a prompt.
*
* <p>The gender of the speaker who creates a speaker model does not need to match the gender of a
* voice that is used with prompts that are associated with that speaker model. For example, a
* speaker model that is created by a male speaker can be associated with prompts that are spoken
* by female voices.
*
* <p>You create a speaker model for a given instance of the service. The new speaker model is
* owned by the service instance whose credentials are used to create it. That same speaker can
* then be used to create prompts for all custom models within that service instance. No language
* is associated with a speaker model, but each custom model has a single specified language. You
* can add prompts only to US English models.
*
* <p>You specify a name for the speaker when you create it. The name must be unique among all
* speaker names for the owning service instance. To re-create a speaker model for an existing
* speaker name, you must first delete the existing speaker model that has that name.
*
* <p>Speaker enrollment is a synchronous operation. Although it accepts more audio data than a
* prompt, the process of adding a speaker is very fast. The service simply extracts information
* about the speaker’s voice from the audio. Unlike prompts, speaker models neither need nor
* accept a transcription of the audio. When the call returns, the audio is fully processed and
* the speaker enrollment is complete.
*
* <p>The service returns a speaker ID with the request. A speaker ID is globally unique
* identifier (GUID) that you use to identify the speaker in subsequent requests to the service.
* Speaker models and the custom prompts with which they are used are supported only for use with
* US English custom models and voices.
*
* <p>**See also:** * [Create a speaker
* model](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-tbe-create#tbe-create-speaker-model)
* * [Rules for creating speaker
* models](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-tbe-rules#tbe-rules-speakers).
*
* @param createSpeakerModelOptions the {@link CreateSpeakerModelOptions} containing the options
* for the call
* @return a {@link ServiceCall} with a result of type {@link SpeakerModel}
*/
public ServiceCall<SpeakerModel> createSpeakerModel(CreateSpeakerModelOptions createSpeakerModelOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createSpeakerModelOptions, "createSpeakerModelOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/speakers"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("text_to_speech", "v1", "createSpeakerModel");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("speaker_name", String.valueOf(createSpeakerModelOptions.speakerName()));
builder.bodyContent(createSpeakerModelOptions.audio(), "audio/wav");
ResponseConverter<SpeakerModel> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SpeakerModel>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.text_to_speech.v1.model.Prompts in project java-sdk by watson-developer-cloud.
the class TextToSpeechTest method testAddCustomPromptWOptions.
// Test the addCustomPrompt operation with a valid options model parameter
@Test
public void testAddCustomPromptWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"prompt\": \"prompt\", \"prompt_id\": \"promptId\", \"status\": \"status\", \"error\": \"error\", \"speaker_id\": \"speakerId\"}";
String addCustomPromptPath = "/v1/customizations/testString/prompts/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the PromptMetadata model
PromptMetadata promptMetadataModel = new PromptMetadata.Builder().promptText("testString").speakerId("testString").build();
// Construct an instance of the AddCustomPromptOptions model
AddCustomPromptOptions addCustomPromptOptionsModel = new AddCustomPromptOptions.Builder().customizationId("testString").promptId("testString").metadata(promptMetadataModel).file(TestUtilities.createMockStream("This is a mock file.")).build();
// Invoke addCustomPrompt() with a valid options model and verify the result
Response<Prompt> response = textToSpeechService.addCustomPrompt(addCustomPromptOptionsModel).execute();
assertNotNull(response);
Prompt responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, addCustomPromptPath);
// Verify that there is no query string
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
}
use of com.ibm.watson.text_to_speech.v1.model.Prompts in project java-sdk by watson-developer-cloud.
the class TextToSpeechTest method testDeleteCustomPromptWOptions.
// Test the deleteCustomPrompt operation with a valid options model parameter
@Test
public void testDeleteCustomPromptWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "";
String deleteCustomPromptPath = "/v1/customizations/testString/prompts/testString";
server.enqueue(new MockResponse().setResponseCode(204).setBody(mockResponseBody));
// Construct an instance of the DeleteCustomPromptOptions model
DeleteCustomPromptOptions deleteCustomPromptOptionsModel = new DeleteCustomPromptOptions.Builder().customizationId("testString").promptId("testString").build();
// Invoke deleteCustomPrompt() with a valid options model and verify the result
Response<Void> response = textToSpeechService.deleteCustomPrompt(deleteCustomPromptOptionsModel).execute();
assertNotNull(response);
Void responseObj = response.getResult();
assertNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "DELETE");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, deleteCustomPromptPath);
// Verify that there is no query string
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
}
use of com.ibm.watson.text_to_speech.v1.model.Prompts in project java-sdk by watson-developer-cloud.
the class TextToSpeechTest method testListCustomPromptsWOptions.
// Test the listCustomPrompts operation with a valid options model parameter
@Test
public void testListCustomPromptsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"prompts\": [{\"prompt\": \"prompt\", \"prompt_id\": \"promptId\", \"status\": \"status\", \"error\": \"error\", \"speaker_id\": \"speakerId\"}]}";
String listCustomPromptsPath = "/v1/customizations/testString/prompts";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ListCustomPromptsOptions model
ListCustomPromptsOptions listCustomPromptsOptionsModel = new ListCustomPromptsOptions.Builder().customizationId("testString").build();
// Invoke listCustomPrompts() with a valid options model and verify the result
Response<Prompts> response = textToSpeechService.listCustomPrompts(listCustomPromptsOptionsModel).execute();
assertNotNull(response);
Prompts responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, listCustomPromptsPath);
// Verify that there is no query string
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
}
Aggregations