audio - Python: convert hex bytestream to “int16" -


so i'm working incoming audio watson text speech. want play sound when data arrives python websocket nodejs. example of data i'm sending websocket:

  <buffer e3 f8 28 f9 fa f9 5d fb 6c fc a6 fd 12 ff b3 00 b8 02 93 04 42 06 5b 07 e4 07 af 08 18 0a 95 0b 01 0d a2 0e a4 10 d7 12 f4 12 84 12 39 13 b0 12 3b 13 ... > 

so data arrives hex bytestream , try convert sounddevice can read/play. (see documentation: types 'float32', 'int32', 'int16', 'int8' , 'uint8' can used streams , functions.) how can convert this? tried something, when run code hear noise, nothing recognizable. here can read parts of code:

def onmessage(self, payload, isbinary):     = payload.encode('hex')     queue.put(a) 

after receive bytesstream , convert hex, try send incoming bytestream sounddevice:

def stream_audio():     sd.outputstream(channels=1, samplerate=24000, dtype='int16', callback=callback):         sd.sleep(int(20 * 1000))   def callback(outdata, frames, time, status):     global reststuff, i, string     length = frames     while len(reststuff) < length:         = queue.get()         reststuff +=     returnstring = reststuff[:length]     reststuff = reststuff[length:]      char in returnstring:         += 1         string += char         if % 2 == 0:             print string             outdata[:] = int(string, 16)             string = "" 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -