Android直接播放麦克风采集到的声音

Android直接播放麦克风采集到的声音

Android直接播放麦克风采集到的声音_android 调用麦克风获取语音流-CSDN博客

复制代码
 class RecordThread extends Thread{  
    static final int frequency = 44100;  
    static final int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO;  
    static final int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;  
@Override  
public void run() {  
    // TODO Auto-generated method stub  
    int recBufSize = AudioRecord.getMinBufferSize(frequency,  
            channelConfiguration, audioEncoding)*2;  
    int plyBufSize = AudioTrack.getMinBufferSize(frequency,  
            channelConfiguration, audioEncoding)*2;  
      
    AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, frequency,  
            channelConfiguration, audioEncoding, recBufSize);  
  
    AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, frequency,  
            channelConfiguration, audioEncoding, plyBufSize, AudioTrack.MODE_STREAM);  
      
    byte[] recBuf = new byte[recBufSize];  
    audioRecord.startRecording();  
    audioTrack.play();  
    while(true){  
        int readLen = audioRecord.read(recBuf, 0, recBufSize);  
        audioTrack.write(recBuf, 0, readLen);  
    }  
    audioTrack.stop();  
    audioRecord.stop();  
}  
  }  



RecordThread rec = new RecordThread();  
rec.start(); 

<uses-permission android:name="android.permission.RECORD_AUDIO"/>  
相关推荐
huwuhang14 小时前
Winkawaks街机游戏模拟器整合ROM版 1.65 汉化修正完整版 2026.03.30
android·游戏·游戏机
yitian_hm14 小时前
MySQL主从复制与读写分离实战指南
android·mysql·adb
NEGl DRYN14 小时前
Plugin ‘mysql_native_password‘ is not loaded`
android·数据库·mysql
Derrick__115 小时前
Android混淆和加密技术
android·jvm·python
sunwenjian88616 小时前
MySQL加减间隔时间函数DATE_ADD和DATE_SUB的详解
android·数据库·mysql
ictI CABL16 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
放学以后Nicetry18 小时前
Android SELinux 指南:从基本概念到实战修复
android
CCIE-Yasuo18 小时前
《永恒战士2-无双战神》无限金币版(提供apk下载)安卓Android逆向记录学习-Deepseek-AI辅助
android·java·学习·游戏
jzlhll12319 小时前
kotlin flow去重distinctUntilChanged vs distinctUntilChangedBy
android·开发语言·kotlin
渡我白衣20 小时前
【MySQL基础】(3):MySQL库与表的操作
android·数据库·人工智能·深度学习·神经网络·mysql·adb