Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tbaggs opened this issue Aug 14, 2018 · 2 comments

Comments

@tbaggs
Copy link

tbaggs commented Aug 14, 2018

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
Copy link
Author

tbaggs commented Aug 14, 2018

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

@tbaggs
Copy link
Author

tbaggs commented Aug 15, 2018

I solved this by doing a

data = b''.join(data)

prior to the bing.recognize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant