2

I am trying to send an audio file (.wav) for speech-to-text using ibm-watson service and websocket-sharp.I'm doing it in an asp.net mvc action by using a sample .wav file of 80kb. While following this tutorial speech-to-text/websockets.

I'm doing the following

                var ws = new WebSocket("wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=" + token);
                ws.OnOpen += ws_OnOpen;
                ws.OnMessage += ws_OnMessage;
                ws.OnClose += ws_OnClose;
                ws.OnError += ws_OnError;

                ws.Connect();

                string startActionjson = "{'action': 'start', 'content-type': 'audio/wav', 'continuous' : true, 'interim_results': true, 'inactivity_timeout': -1,}";
                ws.SendAsync(startActionjson, b =>
                {
                    if (b == true)
                    {
                        //send the audio as binary
                        string filePath = "E:\\Test Folders\\Sample\\test003.wav";
                        byte[] bytes = System.IO.File.ReadAllBytes(filePath);

                        ws.SendAsync(bytes, b1 =>
                        {
                            if(b1)
                                ws.Close();
                        });

                    }
                });

After the start action is sent, my websocket's readystate remains Open but as soon as the line for sending the bytes executes, i receive the following in my OnMessage event

 {
  "name": "error", 
  "error": "Expecting property name: line 1 column 2 (char 1)"
 }

and readystate updates itself as 'Closed'.

I have tried sending the FileStream as well, its doing so on both chrome and firefox. Any help or direction to solution will be highly appreciable.

Thanks

Ali Baig
  • 3,819
  • 4
  • 34
  • 47
  • Hi @Ali Baig , I am also working on watson speech to text api in C# . Do you have any reference link or sample code available for achieving speech to text with watson api – Heemanshu Bhalla Mar 16 '16 at 09:28

1 Answers1

1

I found the solution and there was an issue sending the correct json for action start. I updated it to the following

 string startActionjson = "{\"action\": \"start\", \"content-type\": \"audio/wav\", \"continuous\" : true, \"interim_results\": true}";

Although i tried the json i posted in the question on Json Lint and it's was valid. Strange but nevertheless working

Ali Baig
  • 3,819
  • 4
  • 34
  • 47