流音频到服务器

时间:2018-11-18 11:40:28

标签: android-studio audio stream recording

我正在尝试使用AudioRecorder在Android应用上通过麦克风进行录音,类似这样。如果我要在本地保存文件然后播放它,那么效果很好,但是我需要发送它,所以我需要使用字节:

private int sampleRate = 16000;
private int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private int audioFormat = AudioFormat.ENCODING_PCM_16BIT;

final byte[] buffer = new byte[minBufSize];
int minBufSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, channelConfig,audioFormat, minBufSize*10);
recorder.startRecording();
while(true) {
    //reading data from MIC into buffer
    minBufSize = recorder.read(buffer, 0, buffer.length);
    Map<String, String> params = new HashMap<String, String>()
        {{put("type", "recording");
          put("data", new String(Base64.getEncoder().encode(buffer.toString().getBytes())));
        }};
    this.sendRequest(params); // send these through HTTP POST req
}

尽管在接收端(PHP服务器),我不知道如何将数据保存为任何可播放的格式。这是来自麦克风的音频的不确定记录。任何帮助表示赞赏!

0 个答案:

没有答案