Skip to content

[speech-to-text] Customization does not work when using recognizeUsingWebSocket() method #540

Description

@ota-sandr

Steps to reproduce

// 1) create RecognitionOptions object with customization ID
RecognizeOptions sttOptions = new RecognizeOptions.Builder()
    .customizationId(MY_CUSTOMIZATION_ID).build();
// 2) use websocket interface with these options
sttService.recognizeUsingWebSocket(audioSource, sttOptions, resultCb);

Expected behavior

Recognize results should contain the sentences from customization corpus (including custom words) more likely.

Actual behavior

When I printed the response message from speech-to-text, it contains string:

"warnings": [
   "Unknown arguments: customization_id."
]

Recognized results also do not contain custom words.

JDK version: 1.8.0_112
java-skd version: 3.5.2

Suggested solution

Modify WebSocketManager.java :

public class WebSocketManager {
    // ...
    private class SpeechToTextWebSocketListener implements WebSocketListener {
        private static final String CUSTOMIZATION = "customization_id";
        // ...
        private String buildStartMessage(RecognizeOptions options) {
            JsonObject startMessage = new JsonParser().parse(new Gson().toJson(options)).getAsJsonObject();
            startMessage.remove(MODEL);
            startMessage.remove(CUSTOMIZATION);
            startMessage.addProperty(ACTION, START);
            return startMessage.toString();
        }
        // ...
    }
    // ...
    private WebSocketCall createConnection(RecognizeOptions options) {
        String speechModel = options.model() == null ? "" : "?model=" + options.model();
        if (options.customizationId() != null) {
            speechModel += "&customization_id=" + options.customizationId();
        }
        Builder builder = new Request.Builder().url(url + speechModel);
        // ...
    }
    // ...
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions