我想在我的 Angular 项目上运行 WaveSurfer.js,但它不像我想要的那样工作。WaveSurfer 在索引中完美运行。但是,我想在我的组件中使用 WaveSurfer,但它不起作用。
索引(工作):
<!doctype html>
<html lang="en">
<head>
<script src="assets/js/wavesurfer.min.js"></script><
<script src="wavesurfer.microphone.min.js"></script>
<meta charset="utf-8">
<title>WaveAngular</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
<div id="waveform"></div>
<script src="assets/js/wavesurfer.js">
</script>
</script>
</body>
</html>
组件(不起作用):
<div class="dashboard-voice-parent">
<div class="dashboard-voice-Visualication">
<div id="waveform"></div>
<script src="assets/js/wavesurfer.js"></script>
</div>
<div class="dashboard-voice-buttoncontainer">
<div class="dashboard-voice-buttonborder ">
<button type="button" class="dashboard-voice-animated"
onclick="microphone.pause()" >
<img src="/assets/svg/PauseBTN.png" >
</button>
<button type="button" class="dashboard-voice-VoiceBTN"
onclick="microphone.start()" >
<img src="/asset`enter code here`s/svg/VoiceBTN.png">
</button>
<button type="button" class="dashboard-voice-animated"
onclick="microphone.stopDevice()" >
<img src="/assets/svg/StopBTN.png" >
</button>
</div>
</div>
</div>
错误:
Uncaught ReferenceError: microphone is not defined
at HTMLButtonElement.onclick ((index):17)
这是我在 wavesurfer.js 中的 JavaScript 代码
var
wavesurfer=WaveSurfer.create({container:'#waveform',waveColor:'grey'});
var microphone = Object.create(WaveSurfer.Microphone);
microphone.init({
wavesurfer: wavesurfer
});
microphone.on('deviceReady', function(stream) {
console.log('Device ready!', stream);
});
microphone.on('deviceError', function(code) {
console.warn('Device error: ' + code);
});
microphone.pause();
microphone.play();
microphone.stopDevice();
这是我正在使用的 WaveSurfer:WaveSurfer.Microphone 示例
我希望你们能帮助我解决这个问题!