网络上录制音频,preSET:16位16000, [英] Record audio on web, preset: 16000Hz 16bit

查看:344
本文介绍了网络上录制音频,preSET:16位16000,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
  }
}

function writeString(view, offset, string){
  for (var i = 0; i < string.length; i++){
    view.setUint8(offset + i, string.charCodeAt(i));
  }
}

function encodeWAV(samples){
  var buffer = new ArrayBuffer(44 + samples.length * 2);
  var view = new DataView(buffer);

  /* RIFF identifier */
  writeString(view, 0, 'RIFF');
  /* RIFF chunk length */
  view.setUint32(4, 36 + samples.length * 2, true);
  /* RIFF type */
  writeString(view, 8, 'WAVE');
  /* format chunk identifier */
  writeString(view, 12, 'fmt ');
  /* format chunk length */
  view.setUint32(16, 16, true);
  /* sample format (raw) */
  view.setUint16(20, 1, true);
  /* channel count */
  view.setUint16(22, 2, true);
  /* sample rate */
  view.setUint32(24, sampleRate, true);
  /* byte rate (sample rate * block align) */
  view.setUint32(28, sampleRate * 4, true);
  /* block align (channel count * bytes per sample) */
  view.setUint16(32, 4, true);
  /* bits per sample */
  view.setUint16(34, 16, true);
  /* data chunk identifier */
  writeString(view, 36, 'data');
  /* data chunk length */
  view.setUint32(40, samples.length * 2, true);

  floatTo16BitPCM(view, 44, samples);

  return view;
}

我用这个源$ C ​​$ C记录为我校的考试音频。它记录了44100Hz和16位音频。我想改变录音设置在16000,和16位录制音频。
我试图修改44在功能上连接codeWAV 16个,但没有奏效。

Hi, I am using this source code to record audio for my school exam. It records audio in 44100Hz and 16bit. I want to change recording settings to record audio in 16000Hz and 16bit. I tried modify 44 in function encodeWAV to 16 but it didn't work.

function encodeWAV(samples){
  var buffer = new ArrayBuffer(44 + samples.length * 2);
  var view = new DataView(buffer)

我也尝试过改变floadRToBitPCM。我试图改变44到16,但它也没有工作。

Also I have tried to change floadRToBitPCM. I tried to change 44 to 16 but it also didn't work.

floatTo16BitPCM(view, 44, samples);

可以帮助我解决这个问题?我不知道如何修改此源$ C ​​$ C。

Can you help me with this issue?? I don't know how to modify this source code.

推荐答案

我不相信你可以使用Web API的音频控制采样率......它拿起这是在浏览器之外定义的系统默认采样率...当然随后的录音,您可以通过编程改变你的音频重新采样到任何采样率......大多数音频播放器只能播放标准的采样率媒体......能够呈现16 kHz的关采样率可能会更具挑战性重采样比从44.1到16 kHz

I do not believe you can control sample rate using Web Audio API ... it picks up the system default sample rate which is defined outside the browser ... of course subsequent to recording, you can programmatically alter your audio to resample to any sample rate ... Most audio players can only play media of standard sample rates ... being able to render an off sample rate of 16 kHz might be more challenging than resampling from 44.1 to 16 kHz

这篇关于网络上录制音频,preSET:16位16000,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆