How can we use microphone in google colab?

北城余情 提交于 2021-02-19 08:41:28

问题


OSError Traceback (most recent call last)

<ipython-input-21-4159a88154c9> in <module>()
      7 response = google_images_download.googleimagesdownload()
      8 r = sr.Recognizer()
----> 9 with sr.Microphone() as source:
     10     print("Say something!")
     11     audio = r.listen(source)

/usr/local/lib/python3.6/dist-packages/speech_recognition/init.py in init(self, device_index, sample_rate, chunk_size)

 84 assert 0 <= device_index < count, "Device index out of range ({} devices available; device index should be between 0 and {} inclusive)".format(count, count - 1)
     85 if sample_rate is None:  # automatically set the sample rate to the hardware's default sample rate if not specified
---> 86 device_info = audio.get_device_inf  o_by_index(device_index) if device_index is not None else audio.get_default_input_device_info()
     87 assert isinstance(device_info.get("defaultSampleRate"), (float, int)) and device_info["defaultSampleRate"] > 0, "Invalid device info returned from PyAudio: {}".format(device_info)
     88 sample_rate = int(device_info["defaultSampleRate"])

回答1:


Here's an example that shows how to access a user's camera and microphone:

https://colab.research.google.com/notebooks/snippets/advanced_outputs.ipynb#scrollTo=2viqYx97hPMi

The snippet you linked above attempts to access a microphone in Python. That won't work because there's no microphone attached to the virtual machine which executes Python code in Colab.

Instead, you want to access the microphone of the computer running the web browser. Then, capture data there, and pass it back to the virtual machine for processing in Python.

That's what's shown in the snippet linked above.



来源:https://stackoverflow.com/questions/55701631/how-can-we-use-microphone-in-google-colab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!