#Voice Recognition

50 messages · Page 1 of 1 (latest)

modest stirrup
#

i'm doing a voice command project. Basically, the voice is transcribed into text, and this text is compared with some keyword, and if it is equal to the keyword, it executes a function.
i'm trying to make a function that will open a new tab by searching google whatever is transcribed from the word "search". If the phrase "search potato" is transcribed, the browser will search potato and ignore the word "search".
My problem is that the variable that stores what is transcribed only takes the word "search" and ignores everything that comes after it

    if (transcript == `search`) { // search keyword
        msg.text = 'Searching' // a text-to-speech saying the browser is searching
        speechSynthesis.speak(msg) // a text-to-speech saying the browser is searching
        window.open(`https://www.google.com/search?q=${transcript}`) 
    }

I thought of making a condition that if the transcript has the word search, do the search with the whole phrase, but i don't know how to write this condition within the syntax

note: i was trying to use array to do this, but it is getting the letter that is composing the word "search", Eg: transcript[1] returns e from search

past pine
#

Can you show more code? I can't tell what's happening from what you've shared.

modest stirrup
modest stirrup
# past pine Can you show more code? I can't tell what's happening from what you've shared.

hey

// text to speech
var msg = new SpeechSynthesisUtterance()
var voices = window.speechSynthesis.getVoices()
msg.voice = voices[1]
msg.volume = 1 // 0 to 1
msg.rate = 1 // 0.1 to 10
msg.pitch = 2 // 0 to 2
msg.text = ""
msg.lang = 'pt-br'

// speech to text
var speech = true
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
const recognition = new SpeechRecognition()
recognition.interimResults = true
recognition.lang = 'pt-BR'
const words = document.querySelector('.console')

// receive speech
words.appendChild(voice)
recognition.addEventListener('result', e => {
    const transcript = Array.from(e.results)
        .map(result => result[0])
        .map(result => result.transcript)
        .join('')
    // transcribe speech
    document.getElementById("voice").innerHTML = transcript


    if (transcript == `pesquisar`) { // search
        msg.text = 'Pesquisando' // voice message saying 'searching'
        speechSynthesis.speak(msg) // sends voice message saying 'searching'
        window.open(`https://www.google.com/search?q=${transcript}`)
    }


})

if (speech == true) {
    recognition.start()
    recognition.addEventListener('end', recognition.start)
}


past pine
#

Why are you setting interimResults to true?

modest stirrup
past pine
#

I believe so.

#

It'll ignore non-finalized transcriptions

modest stirrup
past pine
#

You'll have to check and see if e.result is length 1 or if it's longer than that

modest stirrup
# past pine You'll have to check and see if e.result is length 1 or if it's longer than that

both it's not working

 if (transcript == `pesquisar` && transcript.length > 2) {
        msg.text = 'Pesquisando'
        speechSynthesis.speak(msg)

        window.open(`https://www.google.com/search?q=${transcript}`)

    }

 if (transcript == `pesquisar`) {
        msg.text = 'Pesquisando'
        speechSynthesis.speak(msg)
        if (transcript.length > 2) {
            window.open(`https://www.google.com/search?q=${transcript}`)
        }

    }
#

i think the length is getting the letters of the word, not the number of words in the sentence

past pine
#

I'm saying to look at the length. So console.log it. Also I said to get the length of e.results not transcript.

#

Goal is to figure out if your map is broken

modest stirrup
#
words.appendChild(voice)
recognition.addEventListener('result', e => {
    const transcript = Array.from(e.results)
        .map(result => result[0])
        .map(result => result.transcript)
        .join('')
    console.log(e.results.length)
        // transcribe speech
    document.getElementById("voice").innerHTML = transcript

like that?

#

looks like it's getting the amount of letters 💀

past pine
#

e.results isn't a string... Log out e.results to see what it is

modest stirrup
past pine
#

Can you expand 0

modest stirrup
past pine
#

Did you set interim results to false?

modest stirrup
#

yes

#

wait

#

I did ctrl z and it went back to true, I didn't notice lol

#

sorry

past pine
#

Is that the complete transcript of what you said?

modest stirrup
#

yes

past pine
#

So is transcript correct???

#

Does it match what's in e.results?

modest stirrup
#

yes, i said that and the result is correct. What should i do now?

past pine
#

Use transcript???

modest stirrup
#

in this way or should change something?

    if (transcript == `pesquisar`) {
        msg.text = 'Pesquisando'
        speechSynthesis.speak(msg)

        window.open(`https://www.google.com/search?q=${transcript}`)

    }

past pine
#

Yes

modest stirrup
#

did not work :/

past pine
#

Log transcript before the if to make sure it's the correct word

modest stirrup
#

I did this in html, it will transcribe everything I say on the screen

#

so i tried "search test" and nothing happened

past pine
#

Is transcript actually the correct words?

#

Will it match what's the if has

modest stirrup
past pine
#

Then I'm not sure I understand what the problem you're having is

modest stirrup
#

i want to search from what comes after the word "search"

past pine
#

Ok so if you say "search something" you can get the search and the something like so

const sepIndex = transcript.indexOf(" ");
const command = transcript.substr(0, sepIndex);  // this will "search"
const searchFor = transcript.substr(sepIndex + 1);  // this will be "something"
if (command == `pesquisar`) {
    msg.text = 'Pesquisando'
    speechSynthesis.speak(msg)

    window.open(`https://www.google.com/search?q=${searchFor}`)
}
past pine
#

👍

modest stirrup
#

thank you so much I spent 1 day trying to do this