LoginSignup
0
1

More than 1 year has passed since last update.

MacのPythonで音声データを扱う:オーディオデバイスの情報を取得

Posted at

PythonでAudioデータを使ったアプリを作っていきます。
手始めに、オーディオデバイスの情報を取得します

開発環境

・Mac(Mac Book Air 2013)
・MacOS Big Sur(11.5)
・Python 3.9.1
・PortAudio 19.7.0
・PyAudio 0.2.11

参考

PyAudioのAPI仕様を参考にします

手順

1.オーディオデバイスの数を取得
2.全オーディオデバイスに対して情報を取得

import pyaudio

p = pyaudio.PyAudio()

for i in range(0,p.get_device_count()):
    print(p.get_device_info_by_index(i))

私のMacでは以下のような出力が得られました。

{'index': 0, 'structVersion': 2, 'name': 'Built-in Microphone', 'hostApi': 0, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.0029478458049886623, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.01310657596371882, 'defaultHighOutputLatency': 0.1, 'defaultSampleRate': 44100.0}
{'index': 1, 'structVersion': 2, 'name': 'Built-in Output', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': 0.01, 'defaultLowOutputLatency': 0.007551020408163266, 'defaultHighInputLatency': 0.1, 'defaultHighOutputLatency': 0.017709750566893424, 'defaultSampleRate': 44100.0}

オーディオ端子のマイク入力がindexの0番として認識されていますね。
ここで得た情報をもとに、オーディオアプリを作っていけそうです。
今回はここまで。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1