gpt4 book ai didi

android - 安卓如何通过音频流录制麦克风?

转载 作者:行者123 更新时间:2023-12-03 01:51:33 26 4
gpt4 key购买 nike

在我的应用程序中播放音乐时,用户此时应说成麦克风。你能告诉我如何做记录吗?音乐和麦克风的顶部路径。我浏览了MediaRecorder,但我认为没有合适的记录源。

最佳答案

用于通过麦克风录制

通过麦克风开始和停止录制...

开始录制

static MediaRecorder recorder = new MediaRecorder(); 
static String path, filename, time;
static int duration;
public void startRecording() {
try {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
System.currentTimeMillis();
filename = ListenCallState.number + "_" + time + ".amr";
File f = new File(getBaseURL());
f.mkdirs();

path = getBaseURL() + filename;
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();

} catch (Exception {
}
}

停止记录
public static void stopRecording() {
recorder.stop();
recorder.release();
try {
MediaPlayer p = new MediaPlayer();
p.setDataSource(path);
p.prepare();
duration = p.getDuration();
} catch (Exception e) {
}
}

关于android - 安卓如何通过音频流录制麦克风?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39292272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com