gpt4 book ai didi

audio - 我们如何在 google colab 中使用麦克风?

转载 作者:行者123 更新时间:2023-12-02 23:03:09 27 4
gpt4 key购买 nike

OSError Traceback(最后一次调用)

<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"])

最佳答案

下面的示例展示了如何访问用户的摄像头和麦克风:

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

您在上面链接的代码段试图在 Python 中访问麦克风。这行不通,因为没有麦克风连接到在 Colab 中执行 Python 代码的虚拟机。

相反,您想访问运行网络浏览器的计算机的麦克风。然后,在那里捕获数据,并将其传回虚拟机以在 Python 中进行处理。

这就是上面链接的片段中显示的内容。

关于audio - 我们如何在 google colab 中使用麦克风?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55701631/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com