我试图通过getUserMedia录制48000Hz录音.但没有运气.返回的音频MediaStream返回44100Hz.我怎样才能将其设置为48000Hz?
以下是我的代码片段:
var startUsermedia = this.startUsermedia;
navigator.getUserMedia({
audio: true,
//sampleRate: 48000
}, startUsermedia, function (e) {
console.log('No live audio input: ' + e);
});
Run Code Online (Sandbox Code Playgroud)
startUsermedia函数:
startUsermedia: function (stream) {
var input = audio_context.createMediaStreamSource(stream);
console.log('Media stream created.');
// Uncomment if you want the audio to feedback directly
//input.connect(audio_context.destination);
//__log('Input connected to audio context destination.');
recorder = new Recorder(input);
console.log('Recorder initialised.');
},
Run Code Online (Sandbox Code Playgroud)
我尝试更改AudioContext的属性sampleRate,但没有运气.
如何将sampleRate更改为48000Hz?
编辑:我们现在也可以使用闪存解决方案,可以记录和导出48000Hz的wav文件
我正在使用带有NodeJS后端的Google Cloud API for Speech-to-text.应用程序需要能够侦听语音命令,并将它们作为缓冲区传输到后端.为此,我需要在检测到静音时发送前一个音频的缓冲区.
任何帮助,将不胜感激.包括下面的js代码
if (!navigator.getUserMedia)
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true}, success, function (e) {
alert('Error capturing audio.');
});
} else alert('getUserMedia not supported in this browser.');
var recording = false;
window.startRecording = function () {
recording = true;
};
window.stopRecording = function () {
recording = false;
// window.Stream.end();
};
function success(e) {
audioContext = window.AudioContext || window.webkitAudioContext;
context = new audioContext();
// the sample rate is in …
Run Code Online (Sandbox Code Playgroud) javascript node.js audiocontext web-audio-api google-cloud-speech
我正在使用以下方法来播放包含wav数据的字节数组.该函数正在从GWT项目中调用.
此功能播放声音,但它听起来像某种地狱怪物.采样率肯定是正确的(声音是由neospeech生成的)我已经为numberOfSamples尝试了各种值,这似乎只代表音频数据的长度.
numberOfSamples的值大于30000将播放音频文件的全长,但它是乱码且可怕的.
那么,我做错了什么?
function playByteArray(byteArray, numberOfSamples) {
sampleRate = 8000;
if (!window.AudioContext) {
if (!window.webkitAudioContext) {
alert("Your browser does not support any AudioContext and cannot play back this audio.");
return;
}
window.AudioContext = window.webkitAudioContext;
}
var audioContext = new AudioContext();
var buffer = audioContext.createBuffer(1, numberOfSamples, sampleRate);
var buf = buffer.getChannelData(0);
for (i = 0; i < byteArray.length; ++i) {
buf[i] = byteArray[i];
}
var source = audioContext.createBufferSource();
source.buffer = buffer;
source.connect(audioContext.destination);
source.start(0);
}
Run Code Online (Sandbox Code Playgroud) 我已经按照本教程编写了代码:
context = new AudioContext();
play(frequency) {
const o = this.context.createOscillator();
const g = this.context.createGain();
o.connect(g);
g.connect(this.context.destination);
g.gain.exponentialRampToValueAtTime(
0.00001, this.context.currentTime + 1
);
o.frequency.value = frequency;
o.start(0);
}
Run Code Online (Sandbox Code Playgroud)
这样我可以播放从任何注释教程通过传递值表1175
,2794
等
我决定创建一个音符数组,并play
在循环中调用我的函数,它只是没有工作,因为所有音符只是一次播放没有延迟.
你会如何按顺序播放音符数组?
我也在查看那篇文章,但仍然无法弄清楚我如何调整上面的代码.
我有这个 Javascript 代码,当用户点击麦克风按钮时,我用它来捕获用户的音频输入。此代码适用于 Mozila Firefox,但当我在 Google Chrome 中使用它时,它不起作用并在控制台中显示此警告/错误 -The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.
var r = function() {
var e = {}
, t = void 0
, n = getBotConfig()
, r = new Audio("data:audio/wav;base64,")
, o = !1;
if (!n.isIE()) {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var i = new AudioContext;
e.toggleRecording = function(e, t, n, r, s, a, c) {
e.classList.contains("recording") …
Run Code Online (Sandbox Code Playgroud) 我试图使用FileReader readAsArrayBuffer属性读取本地文件.读取成功,在"onload"回调中,我在reader.result中看到了Array Buffer对象.但是Array Buffer只是空的.设置长度,但不设置数据.我如何获得这些数据?
这是我的代码
<!DOCTYPE html>
<html>
<body>
<input type="file" id="file" />
</body>
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
var selFile = files[0];
var reader = new FileReader();
reader.onload = function(e) {
console.log(e.target.result);
};
reader.onerror = function(e) {
console.log(e);
};
reader.readAsArrayBuffer(selFile);
}
document.getElementById('file').addEventListener('change', handleFileSelect, false);
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
reader.result的控制台输出
e.target.result
ArrayBuffer {}
e.target.result.byteLength
25312
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何获取这些数据?有一些安全问题吗?没有错误,不执行onerror.
来自评论:你能告诉我如何访问缓冲区内容吗?我实际上正在尝试播放音频文件AudioContext
...为此我需要缓冲数据...
我试图从Three.js中的AudioContext api映射顶点.
现在,我已成功完成了飞机(非着色器),但遇到了将其应用于气缸的问题.由于圆柱顶点是全矢量,而不是平面的0,我不知道如何将它们映射到frequencyData.
我为寻找音频上下文的未来观众提供了一些额外的功能.
音频背景
function audioLink(){
player = document.getElementById('musicPlayer'),
context = new (window.AudioContext || window.webkitAudioContext),
analyser = context.createAnalyser(),
source = context.createMediaElementSource(player);
source.connect(analyser);
analyser.connect(context.destination);
analyser.fftSize = 256;
frequencyData = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteTimeDomainData(frequencyData);
}
Run Code Online (Sandbox Code Playgroud)
这是我的顶部和底部平面的代码......
function updateVertWave(){
for (var i = 0, len = waveBottom.geometry.vertices.length; i < len; i++) {
waveBottomVert[i].z = frequencyData[i]*6;
waveTopVert[i].z = frequencyData[i]*-6;
}
waveBottom.geometry.verticesNeedUpdate = true;
waveTop.geometry.verticesNeedUpdate = true;
}
Run Code Online (Sandbox Code Playgroud)
在这里
function updateVertCylinder(){
for (var i = 0, len = cylinder.geometry.vertices.length; i < len; i++) {
(STUCK) …
Run Code Online (Sandbox Code Playgroud) 我们有一个博客,每个帖子都包含一个iframe
,当点击播放时,它会使用Web Audio播放声音.
问题是,在页面上有一定数量的帖子后,下一帧会抛出错误:
Uncaught SyntaxError: Failed to construct 'AudioContext': number of hardware contexts reached maximum (6).
在帧之间重用单个AudioContext是不可能的 - window.top
由于同源策略而被禁止.
这是一个简化的例子:http://jsfiddle.net/aobpv7kg/(单击添加框架,直到出现错误 - 在我的情况下为第7帧).
页面中的任意数量的帧可以使用Web Audio吗?或者将每页的帖子数减少到5我们能做什么?
我正在尝试在Angular 5应用的打字稿文件中使用AudioContext。它在Chrome上运行良好,在Safari上不运行。我通过谷歌搜索看到的所有内容都说可以使用,window.webkitAudioContext
但是当打字稿编译器运行时说它在Window类型上不存在时,它立即崩溃。
let context = new AudioContext();
let source = context.createBufferSource();
context
.decodeAudioData(event.body)
.then(x => {
source.buffer = x;
source.connect(context.destination);
source.start(0);
});
Run Code Online (Sandbox Code Playgroud) 我在 React 中使用 AudioContext 接口制作了一个音频可视化工具,我希望用户能够启用和禁用它。
可视化工具工作正常,我也可以禁用它(我只是删除了 vis 组件)
但是,当我想再次启用它时,它告诉我:“InvalidStateError:无法在“AudioContext”上执行“createMediaElementSource”:HTMLMediaElement 之前已连接到不同的 MediaElementSourceNode。”
我想我不能在一个音频元素上同时有 2 个 ElementSource。但我无法解决这个错误。
我尝试在 useEffect 挂钩中返回audiocontext.close() ,以便我可以创建一个新的MediaElementSource(不确定它是否以这种方式工作),但它不会改变任何内容。
也许音频元素上有一个属性可以告诉我是否已经存在 MediaElementSource ?(我什么也没找到)
或者,AudioContext 接口对我来说有点太难了,因为我只是 React 的初学者,而且我只是复制粘贴现有的可视化工具......
谢谢您的帮助!
这是我的可视化组件中的一些代码:
useEffect(() => {
var context = new AudioContext(); //Some visualiser stuff
var src = context.createMediaElementSource(audio);// The error is here
src.crossOrigin = "anonymous";
var analyser = context.createAnalyser();
src.connect(analyser);
analyser.connect(context.destination);
analyser.fftSize = 1024;
// Some canvas stuff here
//
return () => {
context.close() // doesn't work ?
};
}, …
Run Code Online (Sandbox Code Playgroud) audiocontext ×10
javascript ×9
angular5 ×1
arraybuffer ×1
audio ×1
getusermedia ×1
gwt ×1
html5 ×1
iframe ×1
node.js ×1
reactjs ×1
sample-rate ×1
sequence ×1
three.js ×1
typescript ×1
vertex ×1
visualizer ×1
wav ×1