gpt4 book ai didi

javascript - 错误 "LexAudio.conversation is not a constructor"。 React 组件调用 vanilla javascript

转载 作者:行者123 更新时间:2023-11-30 19:47:04 26 4
gpt4 key购买 nike

下面是调用外部 vanilla aws lex javascript 进行对话的 React 组件。调用 new LexAudio.conversation(...) 会出现问题 将外部 js 库导入 React 组件的最佳方式是什么。

class MyComponent extends Component {

startConversation() {
AWS.config.credentials = new AWS.Credentials('', '', null);
AWS.config.region = 'us-east-1';
var waveform = require('./renderer_1.js');
var waveform = window.Waveform();
var config = {
lexConfig: { botName: 'testbot' }
};
var message = document.getElementById('message');
var LexAudio = require('./aws-lex-audio.js');
var conversation = new LexAudio.conversation(config, function (state) {

message.textContent = state + '...';
if (state === 'Listening') {
waveform.prepCanvas();
}
if (state === 'Sending') {
waveform.clearCanvas();
}
}, function (data) {
console.log('Transcript: ', data.inputTranscript, ", Response: ", data.message);
}, function (error) {
//message.textContent = error;
}, function (timeDomain, bufferLength) {
waveform.visualizeAudioBuffer(timeDomain, bufferLength);
});
conversation.advanceConversation();
}
render() {
return (
<div className='Hello'>`enter code here`
<meta charSet="UTF-8" />
<link rel="stylesheet" href="style.css" />
<div className="audio-control" onClick={this.startConversation}>
<p id="audio-control" className="white-circle">
<img alt="new" src="./lex.png" />
<canvas className="visualizer" />
</p>
<p><span id="message" /></p>
</div>
</div>
);
};
}

export default MyComponent;

谢谢你的帮助。

最佳答案

尝试导入页面顶部的 LexAudio。您的大部分进口商品都应放在此处。

类似于:

从 './aws-lex-audio.js' 导入 LexAudio;

代替:

var LexAudio = require('./aws-lex-audio.js');

关于javascript - 错误 "LexAudio.conversation is not a constructor"。 React 组件调用 vanilla javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54845868/

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