From 27c3374ea37a2b10e7fde8f55c104524ee5fd367 Mon Sep 17 00:00:00 2001 From: impressionyang Date: Sat, 13 Jun 2026 14:12:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Linux=20=E4=B8=8B?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE=E5=92=8C=E9=9F=B3=E9=A2=91=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. GlobalShortcuts Portal 缺少 app_id 导致 "An app id is required" 错误 - 添加 app_id="io.impress.voice-input" 到 CreateSession 选项 2. 音频设备索引为 -1 时增加详细诊断日志 - 输出所有可用设备和 Host API 信息 - 当设备总数为 0 时提示安装 ALSA 依赖 Co-Authored-By: Claude Opus 4.7 --- src/audio/audio_capture.cpp | 17 +++++++++++++++++ src/core/caps_lock_voice_hotkey.cpp | 1 + 2 files changed, 18 insertions(+) diff --git a/src/audio/audio_capture.cpp b/src/audio/audio_capture.cpp index 6f5b8d8..26d7a63 100644 --- a/src/audio/audio_capture.cpp +++ b/src/audio/audio_capture.cpp @@ -185,8 +185,25 @@ bool AudioCapture::start(int deviceIndex, int sampleRate, int bufferSizeMs) { // 选择设备 int devIdx = deviceIndex < 0 ? Pa_GetDefaultInputDevice() : deviceIndex; if (devIdx < 0 || devIdx >= Pa_GetDeviceCount()) { + // 诊断:输出所有设备和 Host API 信息 LOG_ERROR(kTag, QString("无效的音频设备索引: %1 (默认设备: %2)") .arg(deviceIndex).arg(Pa_GetDefaultInputDevice())); + LOG_ERROR(kTag, QString("设备总数: %1, Host API 总数: %2") + .arg(Pa_GetDeviceCount()).arg(Pa_GetHostApiCount())); + for (int i = 0; i < Pa_GetDeviceCount(); i++) { + const PaDeviceInfo* info = Pa_GetDeviceInfo(i); + if (info) { + LOG_DEBUG(kTag, QString(" 设备 #%1: %2 (输入通道: %3, 采样率: %4)") + .arg(i).arg(info->name).arg(info->maxInputChannels) + .arg(info->defaultSampleRate)); + } + } + if (Pa_GetDeviceCount() == 0) { + LOG_ERROR(kTag, "PortAudio 未检测到任何音频设备。" + "请确认系统已安装 ALSA/PulseAudio/PipeWire 音频服务," + "并且 libasound2 库可用(Debian: sudo apt install libasound2, " + "Fedora: sudo dnf install alsa-lib)。"); + } return false; } diff --git a/src/core/caps_lock_voice_hotkey.cpp b/src/core/caps_lock_voice_hotkey.cpp index 0f8a2c5..97e39a9 100644 --- a/src/core/caps_lock_voice_hotkey.cpp +++ b/src/core/caps_lock_voice_hotkey.cpp @@ -87,6 +87,7 @@ bool CapsLockVoiceHotkey::start() { QVariantMap options; options["handle_token"] = requestToken; options["session_handle_token"] = sessionToken; + options["app_id"] = "io.impress.voice-input"; QDBusMessage reply = portal.call("CreateSession", options); if (reply.type() == QDBusMessage::ErrorMessage) {