list_devices (agentcall/coreaudio.py)

callpilot · src/agentcall/coreaudio.py · python · Apache-2.0
voice, tag:knn-classified

Enumerates macOS CoreAudio devices for ffmpeg audio_device_index.

# Source: https://github.com/tianye1999/callpilot | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""CoreAudio 设备枚举(macOS 专用,ctypes 直调,无第三方依赖)。

ffmpeg 的 audiotoolbox ``-audio_device_index`` 用的是 kAudioHardwarePropertyDevices
**全设备数组序号**(含只输入的设备),实测证实:给只输入设备的序号会
AudioQueueStart(-66637) 失败,给有输出的序号成功。故本模块返回全数组序号,
与 ffmpeg 对齐。(注意:这不是「输出设备中的序位」——曾误改成序位导致下行
落到只输入的 AC Interface、对端听不到。)
"""

from __future__ import annotations

import ctypes
import struct


def _fourcc(code: str) -> int:
    return struct.unpack(">I", code.encode("ascii"))[0]


_KA_SYSTEM_OBJECT = 1
_KA_DEVICES = _fourcc("dev#")
_KA_DEVICE_NAME = _fourcc("name")
_KA_SCOPE_GLOBAL = _fourcc("glob")
_KA_SCOPE_OUTPUT = _fourcc(

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key