You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android与iOS录音UX统一:系统音效禁用与启用技术问询

统一Android与iOS录音体验的音效处理方案

Android端:禁用SpeechRecognizer的系统录音音效

针对使用SpeechRecognizer类的场景,系统录音开始/结束音效由语音识别服务控制,可通过以下方式禁用:

  • 在启动识别的Intent中添加参数,关闭音频反馈:
    Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    // 通用参数:禁用官方识别服务的音频反馈
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_ENABLE_INOFFICIAL_SPEECH_RECOGNIZER, true);
    // 部分定制系统适配参数
    recognizerIntent.putExtra("android.speech.extra.DISABLE_AUDIO_FEEDBACK", true);
    
  • 若上述参数无效,可尝试修改录音的音频流类型为AudioManager.STREAM_VOICE_CALL,但该方式可能影响语音识别准确率,需测试验证。

iOS端:为AVAudioEngine+SFSpeechRecognizer添加录音音效

iOS原生SFSpeechRecognizer配合AVAudioEngine默认无系统录音音效,需手动播放音效文件,具体实现如下:

方式1:使用系统内置音效

利用AudioToolbox框架调用系统预设的音效ID:

import AudioToolbox

// 录音启动前播放开始音效(ID 1114为系统录音开始音效)
AudioServicesPlaySystemSound(1114)
// 启动录音流程
try? audioEngine.start()

// 录音停止后播放结束音效(ID 1115为系统录音结束音效)
audioEngine.stop()
audioEngine.inputNode.removeTap(onBus: 0)
AudioServicesPlaySystemSound(1115)

方式2:使用自定义音效文件

将自定义的录音开始/结束音频文件添加到项目中,通过AVAudioPlayer播放:

import AVFoundation

// 全局声明音效播放器
var startSoundPlayer: AVAudioPlayer?
var endSoundPlayer: AVAudioPlayer?

// 初始化播放器(建议在页面加载时执行)
func setupSoundPlayers() {
    // 加载开始音效
    if let startUrl = Bundle.main.url(forResource: "record_start", withExtension: "wav") {
        startSoundPlayer = try? AVAudioPlayer(contentsOf: startUrl)
        startSoundPlayer?.prepareToPlay()
    }
    // 加载结束音效
    if let endUrl = Bundle.main.url(forResource: "record_end", withExtension: "wav") {
        endSoundPlayer = try? AVAudioPlayer(contentsOf: endUrl)
        endSoundPlayer?.prepareToPlay()
    }
}

// 录音启动时播放
startSoundPlayer?.play()
try? audioEngine.start()

// 录音停止时播放
audioEngine.stop()
audioEngine.inputNode.removeTap(onBus: 0)
endSoundPlayer?.play()

内容的提问来源于stack exchange,提问作者user2146414

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 02:58:01