I’m building a speech recognition + processing tool with PHP, and I’ve just run in to a problem that I’m not too sure how to fix..
Basically, if a user says hi, I’ve got it to reply with a random greeting from a list of about 30 different greetings, then base the rest of the conversation in a similar tone.
Now to the problem, in more complex sentences, the user could say something like ‘play fireflies by owl city’, or ‘listen to fireflies by owl city’, or ‘hi, can I listen to fireflies by owl city’ understandably, those are requests to play music.
The problem with that, is when a sentence has so many variables, how does one test for the existence of listen, play, and the song name? Basically I assume I have to strip the sentence of all those useless words and only interpret ‘listen/play fireflies owl city’.
Also what I plan to do with ‘listen’ is to trigger a ‘listen’ function which runs the YouTube search API, opens it in a new tab, or returns YouTube search url, depending on the client.
Does anyone know how to strip down sentences like that with PHP’s preg_match? Or any other way? I’ve been trying for the last few hours, lol.
Cheers, very grateful for any and all responses 🙂
Linguistic parsing is pretty complex, and not something for regexp: but to start, you need to be able to identify the “key” words such as nouns, verbs, adjectives, etc and analyse those to determine meaning. Tools such as a brill parser would help with the first part.
There’s a fairly comprehensive list of part of speech analyzers here