respeaker / respeaker_python_library

To build voice enabled objects/applications with Python and ReSpeaker
Apache License 2.0
149 stars 75 forks source link

Getting TypeError: memoryview: a bytes-like object is required, not 'str' in Bing Speech Recognize #44

Open tbaggs opened 6 years ago

tbaggs commented 6 years ago

I updated the Bing Speech uri to the current supported URI for Bing Speech. However, I now get the following error when sending data to the Bing endpoint. Has anyone updated their Bing Speech API file to the current endpoint? https://docs.microsoft.com/en-us/azure/cognitive-services/speech/getstarted/getstartedrest?tabs=Powershell

New Bing URI: url = 'https://speech.platform.bing.com/speech/recognition/interactive/cognitiveservices/v1?language=en-US'

Exception in thread Thread-1: Traceback (most recent call last): File "/home/pi/source/respeaker_python_library/examples/bing_translator.py", line 23, in task text = bing.recognize(data) File "/home/pi/source/respeaker_python_library/examples/bing_speech_api.py", line 111, in recognize response = self.session.post(url, params=params, headers=headers, data=data) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 535, in post return self.request('POST', url, data=data, json=json, kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 488, in request resp = self.send(prep, send_kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 609, in send r = adapter.send(request, **kwargs) File "/usr/lib/python3/dist-packages/requests/adapters.py", line 443, in send for i in request.body: File "/home/pi/source/respeaker_python_library/examples/bing_speech_api.py", line 83, in generate yield self.get_wav_header() File "/home/pi/source/respeaker_python_library/examples/bing_speech_api.py", line 189, in get_wav_header w.writeframes('') File "/usr/lib/python3.5/wave.py", line 427, in writeframes self.writeframesraw(data) File "/usr/lib/python3.5/wave.py", line 415, in writeframesraw data = memoryview(data).cast('B') TypeError: memoryview: a bytes-like object is required, not 'str'

tbaggs commented 6 years ago

This is using the 4mic array for Raspberry Pi on the current Raspbian as of June 2018.

tbaggs commented 6 years ago

I solved this by doing a

data = b''.join(data)

prior to the bing.recognize