Azure-Samples/SpeechToText-WebSockets-Javascript

Web Socket connection get closed

DineshGuptaa opened this issue · 2 comments

Hi,

I want to make hands-free service for the mobile user so that user can speak and that should convert into text. I am implementing using Golang. I am refering https://docs.microsoft.com/en-us/azure/cognitive-services/speech/api-reference-rest/websocketprotocol

I am creation Gorilla WebSocket connection & getting the response as:

101 Switching Protocols 101 HTTP/1.1 1 1 map[X-Xss-Protection:[1; mode=block] X-Content-Type-Options:[nosniff] Referrer-Policy:[strict-origin-when-cross-origin] X-Msedge-Ref:[Ref A: 15D9AB468CB24BEB99668649AF797A71 Ref B: BOM02EDGE0322 Ref C: 2018-06-26T06:58:40Z] Connection:[Upgrade] Sec-Websocket-Accept:[xA4dpm5gNAwD17GxUXDq/+cXVjg=] X-Frame-Options:[DENY] Content-Security-Policy:[object-src 'none'; form-action 'self'; frame-ancestors 'none'] Date:[Tue, 26 Jun 2018 06:58:39 GMT] Upgrade:[websocket] Strict-Transport-Security:[max-age=31536000]] {0xc0421f3ec0} 0 [] false false map[]

After that I am sending the text message

 path: speech.config
 x-requestid: 7D3CD165552546CF850A480FEBD62007
 x-timestamp: 2018-06-06T06:58:41.990Z
 content-type: application/json

 {"Context":{"system":{"version":"1.0.1"},"os":{"platform":"x86_64","name":"windows","version":"10.0.17134.112"},"device":{"manufacturer":"SpeechSample","model":"SpeechSample","version":"1.0.1"}}}

After sending above message I am getting below error message

read tcp 100.64.145.14:59102->13.107.21.200:443: use of closed network connection

Please help me MS STT implemetion in Golang

Thanks
Dinesh Gupta

Hi All,

I tried to make websocket connection from a single file
I used code from here
https://github.com/gorilla/websocket/blob/master/examples/echo/client.go
and after making a connection I sent the config but I receive the error. code is as below

textMsg := msrecognize.GetHeaders("speech.config", "547578238432049")
config, err := msrecognize.GetSpeechConfig()
textMsg = fmt.Sprintf("%s\n%s", textMsg, config)
err = c.WriteMessage(websocket.TextMessage, []byte(textMsg))

and

func GetSpeechConfig() (string,error) {
    gi := goInfo.GetInfo()
    device := Device{Manufacturer:"JioSample",Model:"JioSample",Version:version}
    os := OS{Platform:"x86_64", Name: gi.GoOS, Version:gi.Core}
    system := System{Version: version}
        context := Context{System: system,OS:os, Device:device}
        config := SpeechConfig{Context:context}
        byt, err := json.Marshal(config)
        if err == nil{
        return string(byt), err
       }else{
	      return "", err
      }
  }
 func GetHeaders(params... string) string{
header := fmt.Sprintf("path: %s\n", params[0])
header += fmt.Sprintf("x-requestid: %s\n",params[1])//request id
header += fmt.Sprintf("x-timestamp: %s\n",GetTimestamp())// timestamp
header += fmt.Sprintf("content-type: %s\n","application/json; charset=utf-8")////content type
return header
}

And received below response from service:

  connecting to wss://speech.platform.bing.com/speech/recognition/interactive/cognitiveservices/v1? format=simple&language=en-US&Ocp-Apim-Subscription-Key=e140575af9064bd8a2e5e47a0b5e829a&X- ConnectionId=9AD09FD5DD244BBCBCA2B8DC8AB91A9B
  read: websocket: close 1007 (invalid payload data): Incorrect message format. Text message contains no header separator

Please help me on the same or suggest me any implementation on Golang. I am stuck here unable to proceed.

Regards,
Dinesh Gupta

Hi All,
Now I am able correct format so that can be accepted by speech.config

textMsg := msrecognize.GetHeaders("speech.config", "547578238432049", "application/json; charset=utf-8")
config, err := msrecognize.GetSpeechConfig()
textMsg = fmt.Sprintf("%s\n%s", textMsg, config)
 -->s := strings.Replace(textMsg, "\n", "\r\n", -1)
err = c.WriteMessage(websocket.TextMessage, []byte(s))

Now I am have different issue. As I am sending the text message, same way I tried to send binary data

textMsg1 := msrecognize.GetHeaders("audio", "547578238432049", "audio/x-wav")
_, err1 := ioutil.ReadFile("C:/Users/dinesh/Desktop/Test.wav")
textMsg = fmt.Sprintf("%s\n%s", textMsg1, string("RIFF,�"))
ss := strings.Replace(textMsg, "\n", "\r\n", -1)\
err1 = c.WriteMessage(websocket.BinaryMessage, []byte(ss))

I am getting below repsonse from service:

websocket: close 1007 (invalid payload data): Incorrect message format. Binary message has invalid header size

Please help me to send send the binary data to speech websocket

Regards,
Dinesh Gupta