Record audio on web, preset: 16000Hz 16bit

后端 未结 4 1046
终归单人心
终归单人心 2021-01-05 08:02
function floatTo16BitPCM(output, offset, input){
  for (var i = 0; i < input.length; i++, offset+=2){
    var s = Math.max(-1, Math.min(1, input[i]));
    output.         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-01-05 08:46

    You are modifying the wrong field. A wave file is a header followed by the data. The wave header is typically 44 bytes long. The value of 44 you are seeing in the sample code is related to that and not to 44100.

    Somewhere in code you have not posted, sampleRate is defined to be 44100. You need to track down that definition and change it to 16000. Depending on the rest of your code and the source of the samples it may not be quite that simple though. For example, if samples are being recorded from a device and the device has been configured to record at 44100 then simply marking the saved waveform as 16000 is not going to have the desired effect. It's just going to make playback 2.75x too slow aka the Barry White effect.

提交回复
热议问题