Building a ChatGPT Clone with Speech To Text Feature using Vue.js 3, VueUse, and Tailwind CSS

Posted by

ChatGPT Clone

ChatGPT Clone

0″ class=”overflow-y-auto max-h-60″>

{{ message.text }}
{{ message.text }}

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”);