简体   繁体   English

使用SoundPool在Android上播放声音,同时使用AudioRecord录制麦克风

[英]Playing sound on Android with SoundPool while Recording microphone with AudioRecord

I'm using AudioRecord to record mic data while at the same time playing sounds with SoundPool. 我正在使用AudioRecord录制麦克风数据,同时使用SoundPool播放声音。 My problem is: When I call startRecording() on the AudioRecord, the SoundPool becomes choppy or stops completely. 我的问题是:当我在AudioRecord上调用startRecording()时,SoundPool变得不稳定或完全停止。 When I call stopRecording() all the cued sounds come in at once. 当我调用stopRecording()时,所有提示的声音都立即进入。 Is there a better library I should use? 我应该使用更好的库吗? I've noticed the Buttons in the app are still responsive and are still able to play their default sounds. 我注意到应用程序中的按钮仍然可以响应,并且仍然能够播放其默认声音。

SoundPool stops playing sounds even when the thread that called AudioRecord.startRecording() has finished. 即使调用AudioRecord.startRecording()的线程已经完成,SoundPool也会停止播放声音。 It doesn't play sounds again until I call AudioRecord.stopRecording(). 在我调用AudioRecord.stopRecording()之前,它不会再次播放声音。 I'd like to do both at once. 我想一次做两个。 Seeing as the sounds I'm playing are short sounds, I thought SoundPool was the correct class to use. 看到我正在播放的声音是短声音,我认为SoundPool是使用的正确类。 If someone knows how the Android UI Button class plays its sounds I could copy that and it should work. 如果有人知道Android UI Button类是如何播放声音的,我可以复制该类,它应该可以工作。

This is in the emulator with the latest Android Studio 1.0.2 这是在具有最新Android Studio 1.0.2的模拟器中

Edit: MediaPlayer is worse, it fails after calling AudioRecord.startRecording() and it has much more latency than SoundPool (when not recording at the same time.) I know SoundPool.play() was being called regularly because of Log statements. 编辑:MediaPlayer更糟,它在调用AudioRecord.startRecording()后失败, 并且它的延迟比SoundPool多(当不同时记录时。)我知道SoundLogool.play()由于Log语句而被定期调用。

It's just the emulator. 这只是模拟器。 It works on a physical Android device. 它可以在物理Android设备上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM