ChatGPT Clone
const app = Vue.createApp({
data() {
return {
messages: [],
inputMessage: “”,
isListening: false
};
},
methods: {
sendMessage() {
if (this.inputMessage) {
this.messages.push({ text: this.inputMessage, from: ‘user’ });
this.inputMessage = “”;
}
},
toggleSpeechToText() {
if (!this.isListening) {
this.isListening = true;
const recognition = new window.webkitSpeechRecognition();
recognition.lang = “en-US”;
recognition.onresult = (event) => {
this.inputMessage = event.results[0][0].transcript;
this.sendMessage();
};
recognition.start();
} else {
this.isListening = false;
recognition.stop();
}
}
}
});
app.mount(“#app”);