如何配置 OpenSL 以使用除主扬声器或耳机以外的耳机 [英] How to configure OpenSL to work with ear speaker other than main speaker or headphones
问题描述
我在 android NDK 中尝试过原生音频代码示例.当我尝试录制一些语音然后播放时,它工作正常.它使用主扬声器(扬声器)进行语音播放.我想修改代码,以便在耳机而不是主扬声器中播放语音.有什么帮助吗?
I've tried the native-audio code sample in android NDK. When i try to record some speech and then play it back it works fine. It uses the main speaker(loud speaker) for the speech playback. I want to modify the code so that the speech is played in the ear speaker instead of the main speaker. Any help?
推荐答案
我解决了这个问题,我找到了一个相关主题的google group.这真的很有帮助.这是链接:https://groups.google.com/forum/#!topic/android-ndk/O-hufEm20cU
I solved the problem and I've found a google group of related topic. It was really helpful. Here's the link: https://groups.google.com/forum/#!topic/android-ndk/O-hufEm20cU
我在 Android NDK 提供的本机音频示例中对其进行了测试.您必须先获取android配置的接口,然后在创建音频播放器后将流类型设置为STREAM_VOICE.
I tested it in the native-audio example provided with android NDK. You've to take interface of android configuration first and then set stream type to STREAM_VOICE after creating the audio player.
// Code for working with ear speaker by setting stream type to STREAM_VOICE
SLAndroidConfigurationItf playerConfig;
result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_ANDROIDCONFIGURATION, &playerConfig);
SLint32 streamType = SL_ANDROID_STREAM_VOICE;
result = (*playerConfig)->SetConfiguration(playerConfig, SL_ANDROID_KEY_STREAM_TYPE, &streamType, sizeof(SLint32));
这篇关于如何配置 OpenSL 以使用除主扬声器或耳机以外的耳机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!