我试图使用RecordRTC.js从麦克风录制音频,并将其上传到nancyfx服务器。
出于测试目的,我只是尝试上传音频流并将其保存到wav文件中。然而,我的要求是,在220 is时,流被保存为16位。
问题是,当我使用标准配置(没有recordRtcOptions)记录文件时,我可以上传并保存该文件。当我在记录rate中指定样本速率时,输出文件就是静默。
代码的相关部分位于angularJS服务中,如下所示:
app.service('AudioService', ['$window', '$http', function($window, $http) {
var recordRtcOptions = {
'sample-rate' : 22050
};
navigator.getUserMedia = (
$window.navigator.getUserMedia ||
$window.navigator.webkitGetUserMedia ||
$window.navigator.mozGetUserMedia ||
$window.navigator.msGetUserMedia)
var _recordRTC = {};
navigator.getUserMedia({ audio: true, video: false }, function (stream) {
console.log('starting to initialize getUserMedia');
console.log(recordRtcOptions);
_recordRTC = RecordRTC(stream, recordRtcOptions);
console.log('Finished initializing getUserMedia');
}, function (error) {
console.log('Error initializing media stream: ' + error);
});
var instance = {};
instance.startRecording = function() {
console.log('starting to record...');
console.log('sample rate: ' + _recordRTC.sampleRate);
_recordRTC.startRecording();
};
instance.stopRecording = function(uploadPath) {
console.log('sample rate: ' + _recordRTC.sampleRate);
_recordRTC.stopRecording(function(audioVideoMURL) {
console.log('stopped recording...');
console.log('recordrtc stop sample rate: ' + _recordRTC.sampleRate);
$http({
method : 'POST',
url : uploadPath,
data : _recordRTC.getBlob()
}).success(function(data) {
console.log('POST /audio Success');
}).error(function() {
console.log('POST /audio error');
});
});
};
return instance;
}]);知道问题出在哪里了吗?
发布于 2015-04-28 01:56:43
要理解这个问题,您需要查看RecordRTC.js:
mergeProps复制您提供的配置。reformatProps将“采样率”转换为属性"sampleRate“。StereoRecorder用于记录,内部使用StereoAudioRecorder,本质上类似于金属金刚石/记录器。当您查看它时,它不接受sampleRate作为输入,而是从以下行确定它
var Recorder = function(source, cfg){
...
this.context = source.context;
...
sampleRate: this.context.sampleRate, // --> this is the right way to provide sampleRate在RecordRTC,
var sampleRate = typeof config.sampleRate !== 'undefined' ? config.sampleRate : context.sampleRate || 44100;长话短说,如果您注意到,这里也没有提供采样率,它使用的是context.sampleRate,它是由麦克风提供的采样率,因此仅仅更改配置中的采样率是不够的,因为所做的就是更改写入到.wav文件上的采样值(可以检查函数mergeLeftRightBuffers以进行确认),但是数据仍然会记录在原始采样率上。
如果您真的想修改sampleRate,可以查看在网上录制音频,预设:16000赫兹16位
https://stackoverflow.com/questions/29900450
复制相似问题