如何保存麦克风音频输入? [英] How to save microphone audio input?
问题描述
我需要保存麦克风输入,以便稍后在AudioElement中使用。我这样做以获得麦克风输入:
I need to save microphone input to use later in an AudioElement. I do this to get microphone input:
window.navigator.getUserMedia(audio: true).then((MediaStream stream) {
# what should go here?
});
我应该如何保存音频?
推荐答案
有很多可怕的愚蠢的例子,你可以在当前浏览器窗口中播放当前的音频录制。是否有这样的用例。对于视频,我可以成像,一个想要构建一个Skype的应用程序,并有一个预览窗口,看看你看起来愚蠢的视频,但音频...
There are many horrible stupid examples out there where you are able to play the current audio recording in the current browser window. Is there ever a use case for this. For video I can imaging that one want to build a Skype like application and have a preview window to see if you look stupid on the video, but audio ...
我发现了一个好的帖子:从麦克风到.WAV :getUserMedia和Web Audio
I found one good post though: From microphone to .WAV with: getUserMedia and Web Audio
我已经在链接的文章中移植了一部分代码,显示如何获取数据。
I have ported a part of the code in the linked article that shows how to get hold of the data.
import 'dart:html';
import 'dart:async';
import 'dart:web_audio';
void main() {
window.navigator.getUserMedia(video: true, audio: true).then((MediaStream stream) {
var context = new AudioContext();
GainNode volume = context.createGain();
MediaStreamAudioSourceNode audioInput = context.createMediaStreamSource(stream);
audioInput.connectNode(volume);
int bufferSize = 2048;
ScriptProcessorNode recorder = context.createJavaScriptNode(bufferSize, 2, 2);
recorder.onAudioProcess.listen((AudioProcessingEvent e) {
print('recording');
var left = e.inputBuffer.getChannelData(0);
var right = e.inputBuffer.getChannelData(1);
print(left);
// process Data
});
volume.connectNode(recorder);
recorder.connectNode(context.destination);
/**
* [How to get a file or blob from an object URL?](http://stackoverflow.com/questions/11876175)
* [Convert blob URL to normal URL](http://stackoverflow.com/questions/14952052/convert-blob-url-to-normal-url)
* Doesn't work as it seems blob urls are not supported in Dart
*/
// String url = Url.createObjectUrlFromStream(stream);
// var xhr = new HttpRequest();
// xhr.responseType = 'blob';
// xhr.onLoad.listen((ProgressEvent e) {
// print(xhr.response);
// var recoveredBlog = xhr.response;
// var reader = new FileReader();
//
// reader.onLoad.listen((e) {
// var blobAsDataUrl = reader.result;
// reader.readAsDataUrl(blobAsDataUrl);
// });
// });
// xhr.open('GET', url);
// xhr.send();
/**
* only for testing purposes
**/
// var audio = document.querySelector('audio') as AudioElement;
// audio.controls = true;
// audio.src = url;
});
}
这篇关于如何保存麦克风音频输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!