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

在CodeceptJS+Appium的Android模拟器中如何模拟录音?求相关文档

模拟APP三步录音流程的实现方案(CodeceptJS + Appium + Android模拟器)

可行性确认

Android模拟器完全支持模拟音频输入,结合CodeceptJS和Appium可以通过两种方式实现你的录音流程测试,直接按以下步骤操作即可。

具体实现步骤

1. 提前准备测试音频

先录制好对应三步的音频文件,格式选Android兼容的WAV或MP3:

  • 静音校准:一段无杂音的空白音频(命名silence.wav)
  • 长音“啊”:持续符合APP要求时长的音频(命名ah.wav)
  • 肺活量测试:对应深呼吸的长时长呼气音频(命名deep_breath.wav)

2. 用ADB命令+CodeceptJS方法实现(兼容性广)

不管Appium版本高低都能用,流程是推送音频到模拟器,再用ADB命令触发播放作为录音输入:

// 第一步:静音校准
await I.pushFile('/sdcard/silence.wav', './test_audio/silence.wav');
await I.executeShellCommand('adb shell am start -a android.intent.action.MEDIA_PLAY_FROM_URI -d file:///sdcard/silence.wav');
await I.wait(3); // 等待APP完成校准,时长按实际调整

// 第二步:录制长音"啊"
await I.pushFile('/sdcard/ah.wav', './test_audio/ah.wav');
await I.executeShellCommand('adb shell am start -a android.intent.action.MEDIA_PLAY_FROM_URI -d file:///sdcard/ah.wav');
await I.wait(5);

// 第三步:深呼吸测试
await I.pushFile('/sdcard/deep_breath.wav', './test_audio/deep_breath.wav');
await I.executeShellCommand('adb shell am start -a android.intent.action.MEDIA_PLAY_FROM_URI -d file:///sdcard/deep_breath.wav');
await I.wait(8);

3. 用Appium 2.0+专属API(更简洁)

如果你的Appium是2.0及以上版本,可直接用mobile: simulateAudioInput命令注入音频流:

// 静音校准
await I.executeScript('mobile: simulateAudioInput', {
  audioPath: './test_audio/silence.wav',
  duration: 3000 // 持续3秒,单位毫秒
});

// 长音"啊"
await I.executeScript('mobile: simulateAudioInput', {
  audioPath: './test_audio/ah.wav',
  duration: 5000
});

// 深呼吸测试
await I.executeScript('mobile: simulateAudioInput', {
  audioPath: './test_audio/deep_breath.wav',
  duration: 8000
});

相关文档查找方向

  • CodeceptJS:查看官方文档中pushFile、executeShellCommand方法的说明,以及Appium集成章节
  • Appium:搜索Android驱动的mobile: simulateAudioInput命令文档,还有ADB设备控制的相关内容
  • Android开发者文档:查阅模拟器音频输入的支持参数,以及ADB media命令的用法

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 01:06:30