public WebSocket recognizeUsingWebSocket ( RecognizeOptions recognizeOptions , RecognizeCallback callback ) { Validator . notNull ( recognizeOptions , "recognizeOptions cannot be null" ) ; Validator . notNull ( recognizeOptions . audio ( ) , "audio cannot be null" ) ; Validator . notNull ( callback , "callback cannot be null" ) ; HttpUrl . Builder urlBuilder = HttpUrl . parse ( getEndPoint ( ) + "/v1/recognize" ) . newBuilder ( ) ; if ( recognizeOptions . model ( ) != null ) { urlBuilder . addQueryParameter ( "model" , recognizeOptions . model ( ) ) ; } if ( recognizeOptions . customizationId ( ) != null ) { urlBuilder . addQueryParameter ( "customization_id" , recognizeOptions . customizationId ( ) ) ; } if ( recognizeOptions . languageCustomizationId ( ) != null ) { urlBuilder . addQueryParameter ( "language_customization_id" , recognizeOptions . languageCustomizationId ( ) ) ; } if ( recognizeOptions . acousticCustomizationId ( ) != null ) { urlBuilder . addQueryParameter ( "acoustic_customization_id" , recognizeOptions . acousticCustomizationId ( ) ) ; } if ( recognizeOptions . baseModelVersion ( ) != null ) { urlBuilder . addQueryParameter ( "base_model_version" , recognizeOptions . baseModelVersion ( ) ) ; } String url = urlBuilder . toString ( ) . replace ( "https://" , "wss://" ) ; Request . Builder builder = new Request . Builder ( ) . url ( url ) ; setAuthentication ( builder ) ; setDefaultHeaders ( builder ) ; OkHttpClient client = configureHttpClient ( ) ; return client . newWebSocket ( builder . build ( ) , new SpeechToTextWebSocketListener ( recognizeOptions , callback ) ) ; }
Sends audio and returns transcription results for recognition requests over a WebSocket connection . Requests and responses are enabled over a single TCP connection that abstracts much of the complexity of the request to offer efficient implementation low latency high throughput and an asynchronous response . By default only final results are returned for any request ; to enable interim results set the interimResults parameter to true .