Comments (1)
here is a solution to replace "onend", but even though I got the solution, I'm still curious why "onend" doesn't work.
const jawaban = (text) => {
const voices = window.speechSynthesis.getVoices();
const indonesianVoice = voices.find((voice) => voice.lang === "id-ID");
if (indonesianVoice) {
const utterance = new SpeechSynthesisUtterance(text);
utterance.voice = indonesianVoice;
window.speechSynthesis.speak(utterance);
utterance.onend = function () {
window.speechSynthesis.cancel();
window.location.reload();
};
} else {
console.log("Suara bahasa Indonesia tidak ditemukan.");
const utterance = new SpeechSynthesisUtterance(text);
window.speechSynthesis.speak(utterance);
utterance.onend = function () {
window.speechSynthesis.cancel();
window.location.reload();
};
}
};
const getAllCommand = async (voice) => {
const tokenPemilik =
"ssIy*|1HV@u226ht]r{5f9T]83ak#z_Diu|{|#h.TGdp,pAnt3k^dKvXH|a4iC$@!f&gq3V98E,qbMxk9^DKP0b_n(FMZ&@M$f3";
try {
const response = await axios.post(
"http://localhost:4000/users/getAllCommand",
{ tokenPemilik }
);
const dataCommand = response.data;
if (dataCommand) {
let exactMatchingCommand = null;
for (let i = 0; i < dataCommand.length; i++) {
if (dataCommand[i] === voice) {
exactMatchingCommand = dataCommand[i];
break;
}
}
if (exactMatchingCommand !== null) {
console.log(`Perintah yang sangat cocok dengan "${voice}":`);
console.log(exactMatchingCommand);
jawaban(exactMatchingCommand);
} else {
console.log(
`Tidak ada perintah yang sangat cocok dengan "${voice}".`
);
}
}
} catch (error) {
console.error("Error fetching command data:", error);
}
};
if (lastTranscript) {
const voice = lastTranscript.toLowerCase();
getAllCommand(voice);
setLastTranscript("");
}
useEffect(() => {
if (browserSupportsSpeechRecognition) {
SpeechRecognition.startListening({
continuous: true,
language: "id",
});
}
}, [browserSupportsSpeechRecognition]);
useEffect(() => {
if (transcript.trim() !== "") {
setLastTranscript(transcript);
if (resetTimeout) {
clearTimeout(resetTimeout);
}
const timeoutId = setTimeout(() => {
resetTranscript();
}, 3000);
setResetTimeout(timeoutId);
}
}, [transcript, resetTranscript]);
from react-speech-recognition.
Related Issues (20)
- (browserSupportsContinuousListening): does not exist on useSpeechRecognition 😬
- regeneratorRuntime is not defined when using react with vite HOT 7
- Update/Remove Speechly Support
- Final transcript is always empty
- It is not working in mozilla firefox
- Hi it not working in mobile Chrome and some desktop HOT 3
- regeneratorRuntime is not defined HOT 9
- Issue in Commands
- Can you create a plane JavaScript library for this?
- requesting Speech to text for Tamil language
- Reference Error
- Uncaught (in promise) TypeError: Cannot read properties of null HOT 1
- not working after deployment HOT 1
- browserSupportsSpeechRecognition returns true on Chrome iOS when it should be false HOT 1
- startListening is not a function HOT 2
- Working on Edge in MacOS
- Stopped working after latest chrome update HOT 4
- The speechrecogination dosen't work HOT 2
- Is there any way to change which microphone it uses?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-speech-recognition.