話說從頭,年前友人偶訪談及 ReSpeaker Raspbian Jessie 相容性問題 ?意外引發
PyAudio
PyAudio provides Python bindings for PortAudio, the cross-platform audio I/O library. With PyAudio, you can easily use Python to play and record audio on a variety of platforms, such as GNU/Linux, Microsoft Windows, and Apple Mac OS X / macOS.
PyAudio is inspired by:
- pyPortAudio/fastaudio: Python bindings for PortAudio v18 API.
- tkSnack: cross-platform sound toolkit for Tcl/Tk and Python.
錯誤訊息
pi@raspberrypi:~ ipython3 Python 3.5.3 (default, Jan 19 2017, 14:11:04) Type "copyright", "credits" or "license" for more information. IPython 5.1.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: import pyaudio In [2]: pyaudio.get_portaudio_version_text() Out[2]: 'PortAudio V19.6.0-devel, revision 396fe4b6699ae929d3a685b3ef8a7e97396139a4' In [3]: pyaudio.get_portaudio_version() Out[3]: 1246720 In [4]: p = pyaudio.PyAudio() ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front ... In [5]: p.get_device_count() Out[5]: 10 In [6]: p. get_default_input_device_info() Out[6]: {'defaultHighInputLatency': 0.034829931972789115, 'defaultHighOutputLatency': -1.0, 'defaultLowInputLatency': 0.005804988662131519, 'defaultLowOutputLatency': -1.0, 'defaultSampleRate': 44100.0, 'hostApi': 0, 'index': 2, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'name': 'seeed-4mic-voicecard: - (hw:1,0)', 'structVersion': 2} In [7]: p.get_default_output_device_info() Out[7]: {'defaultHighInputLatency': -1.0, 'defaultHighOutputLatency': 0.034829931972789115, 'defaultLowInputLatency': -1.0, 'defaultLowOutputLatency': 0.005804988662131519, 'defaultSampleRate': 44100.0, 'hostApi': 0, 'index': 8, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'name': 'default', 'structVersion': 2} In [8]: p.get_device_info_by_index(2) Out[8]: {'defaultHighInputLatency': 0.034829931972789115, 'defaultHighOutputLatency': -1.0, 'defaultLowInputLatency': 0.005804988662131519, 'defaultLowOutputLatency': -1.0, 'defaultSampleRate': 44100.0, 'hostApi': 0, 'index': 2, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'name': 'seeed-4mic-voicecard: - (hw:1,0)', 'structVersion': 2} In [9]:
測試還請參考︰
/sound_recorder.py
Created Jan 28, 2014
Simple script to record sound from the microphone, dependencies: easy_install pyaudio