gpt4 book ai didi

javascript - RTC记录器: TypeError Recorder is not a constructor

转载 作者:行者123 更新时间:2023-11-30 19:18:36 25 4
gpt4 key购买 nike

我正在尝试通过 React 应用程序从浏览器录制 wav 并将其发送到我的 nodeJS API。这在原型(prototype) html5 示例中运行良好。但现在我正在将它移动到 React/Typescript。我对 typescript 还很陌生,所以一切都感觉有点老套。

我正在使用 RecordRTC,到目前为止的代码是:

声明文件,因为 recordRTC 没有 @types/recordrtc:

declare module "recordrtc";

实际代码:

startRecording() {
this.record = true
this.captureUserMedia((stream: any) => {
this.recordAudio = RecordRTC(stream, { recorderType: 'StereoAudioRecorder', type: 'audio', mimeType: 'audio/wav' });
this.recordAudio.startRecording();
});
}

当我调用 startRecording 时,我得到了这个:

Uncaught TypeError: Recorder is not a constructor
at initRecorder (RecordRTC.js:87)
at Object.startRecording (RecordRTC.js:70)
at PracticeScreen.tsx:143

在 chrome 浏览器中显示的是:

enter image description here我猜它与 .d.ts 文件有关,但我什至不知道从哪里开始。

最佳答案

The RecordRTC documentation显示 recorderType 需要一个类构造函数,但您的示例将其设置为一个字符串。您可以将其设置为 StereoAudioRecorder 的类构造函数像这样:

RecordRTC(
stream,
{
recorderType: StereoAudioRecorder, // <-------- class constructor not string
type: 'audio',
mimeType: 'audio/wav'
},
);

关于javascript - RTC记录器: TypeError Recorder is not a constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57732632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com