Angular Recorder不是构造函数

时间:2019-12-05 10:06:32

标签: javascript angular commonjs

在Angular 8中,我想将通过浏览器捕获的音频转换为ogg格式。为此,我正在使用opus-recorder库:https://github.com/chris-rudmin/opus-recorder

我做了npm install opus-recorder

  const opusRecorder = require('opus-recorder');

  startRecording() {

    var options = {
      encoderPath: './assets/encoderWorker.min.js'
    };

    let recorder = new opusRecorder.Recorder(options);

    recorder.start().catch(function(e) {
      console.log('Error encountered:', e.message );
    });
  }

github存储库中说The Recorder object is available in the global namespace and supports CommonJS and AMD imports.

调用startRecording()时出现以下错误:

  

错误TypeError:opusRecorder.Recorder不是构造函数

我正确使用库了吗?我可以正确导入吗?可以在Angular中使用吗?

1 个答案:

答案 0 :(得分:1)

我先做import * as opusRecorder from 'opus-recorder';然后做let recorder = new opusRecorder1(options);