简体   繁体   English

Angular 浏览器录音

[英]Angular audio recording in browser

I found an example of how to setup an angular app to record audio here: https://medium.com/@coolchoudharyvijay/use-mic-in-angular-to-record-audio-simplified-1374d89718d3我在这里找到了一个如何设置 angular 应用程序来录制音频的示例: https://medium.com/@coolchoudharyvijay/use-mic-in-angular-to-record-audio-simplified-1374d89718d3

works like a charm locally, but when I build it and throw it on a server, I get this error: ERROR TypeError: Cannot read properties of undefined (reading 'getUserMedia') and ERROR TypeError: Cannot read properties of undefined (reading 'stop')在本地工作就像一个魅力,但是当我构建它并将其扔到服务器上时,我收到此错误:错误类型错误:无法读取未定义的属性(读取'getUserMedia')和错误类型错误:无法读取未定义的属性(读取'停止')

any ideas why it would work locally but not on a server?任何想法为什么它会在本地工作而不是在服务器上工作?

here's the type script code (which can also be found in the article link above):这是类型脚本代码(也可以在上面的文章链接中找到):

import { Component } from '@angular/core';
declare var $: any;
import * as RecordRTC from 'recordrtc';
import { DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'micRecorder';
//Lets declare Record OBJ
record;
//Will use this flag for toggeling recording
recording = false;
//URL of Blob
url;
error;
constructor(private domSanitizer: DomSanitizer) {}
sanitize(url: string) {
return this.domSanitizer.bypassSecurityTrustUrl(url);
}
/**
* Start recording.
*/
initiateRecording() {
this.recording = true;
let mediaConstraints = {
video: false,
audio: true
};
navigator.mediaDevices.getUserMedia(mediaConstraints).then(this.successCallback.bind(this), this.errorCallback.bind(this));
}
/**
* Will be called automatically.
*/
successCallback(stream) {
var options = {
mimeType: "audio/wav",
numberOfAudioChannels: 1,
sampleRate: 16000,
};
//Start Actuall Recording
var StereoAudioRecorder = RecordRTC.StereoAudioRecorder;
this.record = new StereoAudioRecorder(stream, options);
this.record.record();
}
/**
* Stop recording.
*/
stopRecording() {
this.recording = false;
this.record.stop(this.processRecording.bind(this));
}
/**
* processRecording Do what ever you want with blob
* @param  {any} blob Blog
*/
processRecording(blob) {
this.url = URL.createObjectURL(blob);
console.log("blob", blob);
console.log("url", this.url);
}
/**
* Process Error.
*/
errorCallback(error) {
  this.error = 'Can not play audio in your browser';
}
ngOnInit() {}
}

It should be constraints and not mediaConstraints , see the documentation它应该是constraints而不是mediaConstraints ,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM