音频设备诊断技能 — 列出系统可用音频输入设备并检测其工作状态。触发条件:音频设备异常、需查看可用麦克风或选择合适的音频输入设备。
满足以下条件时加载此技能:
python
import pyaudio
p = pyaudio.PyAudio()
info = p.get_host_api_info_by_index(0)
numdevices = info.get('deviceCount')
print("Available audio input devices:")
for i in range(0, numdevices):
if p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels') > 0:
device_info = p.get_device_info_by_host_api_device_index(0, i)
print(f" Input Device id {i} - {device_info.get('name')}")
p.terminate()
bash
cd D:\coze-local\db
python check_audio_devices.py
text
Available audio input devices:
Input Device id 0 - Microsoft Sound Mapper - Input
Input Device id 1 - 麦克风 (Realtek(R) Audio)
Input Device id 2 - 立体声混音 (Realtek(R) Audio)
Input Device id 3 - CABLE Output (VB-Audio Virtual Cable)
问题原因解决[Errno -9999] Unanticipated host error设备索引不存在运行本诊断脚本,使用有效设备ID[WinError 2] 系统找不到指定文件缺少 ffmpeg已修复:使用 numpy 数组直接传 WhisperUnboundLocalError: stream异常路径未初始化变量已修复:初始化 stream = None``UnicodeEncodeError终端编码限制已修复:添加 safe_print() 函数
设备 ID 0(Microsoft Sound Mapper - Input)是系统默认输入设备,兼容性最好。如果使用虚拟音频设备(如 VB-Cable),请使用对应的设备 ID。
D:\coze-local\db\check_audio_devices.py — 诊断脚本D:\coze-local\db\audio.py — 音频核心模块D:\coze-local\external\clawhub_skills\wake-word-detector\SKILL.md — 唤醒词技能bash
pip install pyaudio