Search in sources :

Example 1 with CreateSpeakerModelOptions

use of com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions in project java-sdk by watson-developer-cloud.

the class TextToSpeechIT method testGetSpeakerModel.

/**
 * Test getSpeakerModel.
 */
@Test
public void testGetSpeakerModel() {
    try {
        CreateSpeakerModelOptions createSpeakerModelOptions = new CreateSpeakerModelOptions.Builder().speakerName("speakerName").audio(new File(RESOURCE + "numbers.wav")).build();
        SpeakerModel speakerModel = service.createSpeakerModel(createSpeakerModelOptions).execute().getResult();
        speakerId = speakerModel.getSpeakerId();
        assertNotNull(speakerModel.getSpeakerId());
        GetSpeakerModelOptions getSpeakerModelOptions = new GetSpeakerModelOptions.Builder().speakerId(speakerId).build();
        SpeakerCustomModels speakerCustomModels = service.getSpeakerModel(getSpeakerModelOptions).execute().getResult();
        assertNotNull(speakerCustomModels.getCustomizations());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DeleteSpeakerModelOptions deleteSpeakerModelOptions = new DeleteSpeakerModelOptions.Builder().speakerId(speakerId).build();
        service.deleteSpeakerModel(deleteSpeakerModelOptions).execute().getResult();
    }
}
Also used : DeleteSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteSpeakerModelOptions) SpeakerModel(com.ibm.watson.text_to_speech.v1.model.SpeakerModel) CreateSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions) GetSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.GetSpeakerModelOptions) File(java.io.File) SpeakerCustomModels(com.ibm.watson.text_to_speech.v1.model.SpeakerCustomModels) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 2 with CreateSpeakerModelOptions

use of com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions in project java-sdk by watson-developer-cloud.

the class TextToSpeechIT method testCreateSpeakerModel.

/**
 * Test createSpeakerModel.
 */
@Test
public void testCreateSpeakerModel() {
    try {
        CreateSpeakerModelOptions createSpeakerModelOptions = new CreateSpeakerModelOptions.Builder().speakerName("speakerName").audio(new File(RESOURCE + "numbers.wav")).build();
        SpeakerModel speakerModel = service.createSpeakerModel(createSpeakerModelOptions).execute().getResult();
        speakerId = speakerModel.getSpeakerId();
        assertNotNull(speakerModel.getSpeakerId());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DeleteSpeakerModelOptions deleteSpeakerModelOptions = new DeleteSpeakerModelOptions.Builder().speakerId(speakerId).build();
        service.deleteSpeakerModel(deleteSpeakerModelOptions).execute().getResult();
    }
}
Also used : DeleteSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteSpeakerModelOptions) SpeakerModel(com.ibm.watson.text_to_speech.v1.model.SpeakerModel) CreateSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions) File(java.io.File) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 3 with CreateSpeakerModelOptions

use of com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions in project java-sdk by watson-developer-cloud.

the class TextToSpeechIT method testListSpeakerModel.

/**
 * Test listSpeakerModel.
 */
@Test
public void testListSpeakerModel() {
    try {
        CreateSpeakerModelOptions createSpeakerModelOptions = new CreateSpeakerModelOptions.Builder().speakerName("speakerName").audio(new File(RESOURCE + "numbers.wav")).build();
        SpeakerModel speakerModel = service.createSpeakerModel(createSpeakerModelOptions).execute().getResult();
        speakerId = speakerModel.getSpeakerId();
        assertNotNull(speakerModel.getSpeakerId());
        Speakers speakers = service.listSpeakerModels().execute().getResult();
        assertNotNull(speakers.getSpeakers());
        assertTrue(speakers.getSpeakers().size() > 0);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DeleteSpeakerModelOptions deleteSpeakerModelOptions = new DeleteSpeakerModelOptions.Builder().speakerId(speakerId).build();
        service.deleteSpeakerModel(deleteSpeakerModelOptions).execute().getResult();
    }
}
Also used : DeleteSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteSpeakerModelOptions) SpeakerModel(com.ibm.watson.text_to_speech.v1.model.SpeakerModel) CreateSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions) Speakers(com.ibm.watson.text_to_speech.v1.model.Speakers) File(java.io.File) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 4 with CreateSpeakerModelOptions

use of com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions in project java-sdk by watson-developer-cloud.

the class TextToSpeechTest method testCreateSpeakerModelWOptions.

// Test the createSpeakerModel operation with a valid options model parameter
@Test
public void testCreateSpeakerModelWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"speaker_id\": \"speakerId\"}";
    String createSpeakerModelPath = "/v1/speakers";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the CreateSpeakerModelOptions model
    CreateSpeakerModelOptions createSpeakerModelOptionsModel = new CreateSpeakerModelOptions.Builder().speakerName("testString").audio(TestUtilities.createMockStream("This is a mock file.")).build();
    // Invoke createSpeakerModel() with a valid options model and verify the result
    Response<SpeakerModel> response = textToSpeechService.createSpeakerModel(createSpeakerModelOptionsModel).execute();
    assertNotNull(response);
    SpeakerModel 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, createSpeakerModelPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("speaker_name"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) SpeakerModel(com.ibm.watson.text_to_speech.v1.model.SpeakerModel) CreateSpeakerModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions) Test(org.testng.annotations.Test)

Example 5 with CreateSpeakerModelOptions

use of com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions 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);
}
Also used : SpeakerModel(com.ibm.watson.text_to_speech.v1.model.SpeakerModel) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Aggregations

SpeakerModel (com.ibm.watson.text_to_speech.v1.model.SpeakerModel)5 CreateSpeakerModelOptions (com.ibm.watson.text_to_speech.v1.model.CreateSpeakerModelOptions)4 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)3 DeleteSpeakerModelOptions (com.ibm.watson.text_to_speech.v1.model.DeleteSpeakerModelOptions)3 File (java.io.File)3 IOException (java.io.IOException)3 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)3 Test (org.junit.Test)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 GetSpeakerModelOptions (com.ibm.watson.text_to_speech.v1.model.GetSpeakerModelOptions)1 SpeakerCustomModels (com.ibm.watson.text_to_speech.v1.model.SpeakerCustomModels)1 Speakers (com.ibm.watson.text_to_speech.v1.model.Speakers)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1