Speech recognition failure

88 views
Skip to first unread message

TSE

unread,
Apr 23, 2020, 11:00:41 AM4/23/20
to DroidScript
Hello guys,

I'm new here and if you wondering why my english is so bad, I'm from Germany.

So yesterday I start working with droidscript and tried to make an digital assistant. 

I used this sample code:


function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
    img = app.CreateImage( "Img/tech.jpg", 1.0, 1.2);
    lay.AddChild( img );
    app.AddLayout( lay );
    
    var s = "<u>Commands</u><br><br>"
        + "\"Computer?\"<br>"
        + "\"What time is it?\"<br>"
        + "\"What day is it?\"<br>"
        + "\"How are you?\"<br>"
        + "\"Exit\"<br>";
    txt = app.CreateText( s, 0.9, 0.8, "Multiline,Html" );
    txt.SetTextSize( 18 );
    lay.AddChild( txt );
    
    
    speech = app.CreateSpeechRec("Parxtial");
    speech.SetOnResult( spracherfassung );
speech.SetOnError( speech_OnError );
app.TextToSpeech( "Hello!", 0.8, 1.3, Listen, "music" );
app.ShowProgress();
 

function Listen()
{
    //app.HideProgress();
speech.Recognize();
}


function spracherfassung( results )
{
    var cmd = results[0].toLowerCase();
    
    if( cmd.indexOf("computer") > -1.1)
    {
                app.TextToSpeech( "What can I do for you?", 0.6, 1.3, Listen, "music" );
                speech.SetOnError();
    }
    else speech.Recognize();
}


function speech_OnError( error )
{
    console.log( "Error" + error );
    
    if( !speech.IsListening() ) speech.Recognize();
}

It runs only, if the line is like this:

  if( cmd.indexOf("computer") > -1.1)

if I have it like this:

  if( cmd.indexOf("computer") > -1)

it does not answer. But thats not the problem. If I do it with the 1.1 it repeats the answer the whole time, until I end the app.
It would be nice, if you could help me. Thanks!

Alan Hendry

unread,
Apr 23, 2020, 11:19:08 AM4/23/20
to DroidScript
Tse,
I did 5 years German in school, but I know no computer related words at all. Your English is OK.
If indexOf() doesn't find your string then it returns -1, or 0 for the first character, 1 for the second, etc
You could try >= 0 or !== -1

I think your option should be Partial (not Parxtial)

Regards

TSE

unread,
Apr 23, 2020, 11:40:11 AM4/23/20
to DroidScript
First at all, thank you very much for the quick reply!

I tried both now, the >=0 and !==-1 but it still does not work or does repeat the text in a loop all the time.
I noticed, that it reacts not only to the word "computer". It reacts to every word I say. 

Alan Hendry

unread,
Apr 23, 2020, 12:05:58 PM4/23/20
to DroidScript
Tse,
I only know (simple) javascript, I'm not part of the DS team
In function Listen you have - speech.Recognize();
Then in function spracherfassung you have - else speech.Recognize();
Are you getting any entries on the error log? console.log( "Error" + error );
Regards, Alan H

TSE

unread,
Apr 23, 2020, 12:23:11 PM4/23/20
to DroidScript
No there are no entries. 
That second speech.Recognize(); is for the reason that it doesn't turn of the speech recognition.
I took the code from the official droidscript website. When you go to the editor there are some samples.
But even the original sample doesn't work 
on my phone.

Steve Garman

unread,
Apr 23, 2020, 12:38:35 PM4/23/20
to DroidScript
Every answer to indexOf will be greater than -1.1 because -1 is the "not found" value so it will try to use every word and not know what to do with it.

I suggest you go back to the original sample. It works on a phone set to English.

If your device is set to German, try changing the first word to its German equivalent and see if it works.

If you are working in English, try replacing the first word with an easy word to pronounce to see if it is struggling with your accent.

parxtial does nothing, so I recommend removing it as pertial will just make your life more difficult.

TSE

unread,
Apr 23, 2020, 1:42:16 PM4/23/20
to DroidScript
Hello thank you for your quick reply, too.
I tried the original sample which is this one:

//Hinweis: Offline-Erkennungs-Engines können in der Datei
//Android Language und Input Einstellungen (empfohlen für die Geschwindigkeit).
//Es können auch Stimmen höherer Qualität heruntergeladen werden.

//Wird aufgerufen, wenn die Anwendung gestartet wird.
function OnStart()
{
    //Erstellen Sie ein Hauptlayout mit vertikal zentrierten Objekten.
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );   
    lay.SetBackground( "/res/drawable/pattern_carbon", "repeat" );

    var s = "<u>Commands</u><br><br>"
        + "\"Computer?\"<br>"
        + "\"What time is it?\"<br>"
        + "\"What day is it?\"<br>"
        + "\"How are you?\"<br>"
        + "\"Exit\"<br>";
    txt = app.CreateText( s, 0.9, 0.8, "Multiline,Html" );
    txt.SetTextSize( 32 );
    lay.AddChild( txt );
  
    //Layout zur App hinzufügen.    
    app.AddLayout( lay );
    
    //Erkennungsobjekt anlegen und Rückrufe setzen.
speech = app.CreateSpeechRec("NoBeep,Parxtial");
speech.SetOnResult( speech_OnResult );
speech.SetOnError( speech_OnError );
//Sagen Sie etwas beim Start (um die Sprachausgabe vorzubereiten).
    app.TextToSpeech( "Your wish is my command", 1, 1.5, Listen );
    app.ShowProgress();
}

//Fangen Sie an zu erkennen.
function Listen()
{
    app.HideProgress();
speech.Recognize();
}

//Wird mit dem/den Erkennungsergebnis(en) aufgerufen.
function speech_OnResult( results, partial )
{
    //Erhalten Sie ein Ergebnis.
    var cmd = results[0].toLowerCase();
    
    //Achten Sie auf Schlüsselsätze.
    if( cmd.indexOf("computer") > -1 )
    {
        //speech.Cancel();
        app.TextToSpeech( "Yes Master?", 1,2, Listen );
    }
    else if( cmd.indexOf("what")>-1 && cmd.indexOf("time")>-1 )
    {
        //speech.Cancel();
        app.TextToSpeech( GetTime(), 1,2, Listen  );
    }
    else if( cmd.indexOf("what")>-1 && cmd.indexOf("day")>-1 )
    {
       // speech.Cancel();
        app.TextToSpeech( GetDay(), 1,2, Listen );
    }
    else if( cmd.indexOf("how")>-1 && cmd.indexOf("you")>-1 )
    {
        //speech.Cancel();
        app.TextToSpeech( "Im feeling good", 1,2, Listen );
    }
    else if( cmd.indexOf("exit")>-1 )
    {
       app.Exit();
    }
    
    //Wiederanlauf der Erkennung.
    else speech.Recognize();
}


//Wird aufgerufen, wenn die Erkennung fehlschlägt.
function speech_OnError( error )
{
    console.log( "Error" + error );
    
    //Wiederanlauf der Erkennung.
    if( !speech.IsListening() ) speech.Recognize();
}

//Ermittelt die aktuelle Uhrzeit.
function GetTime()
{
    var d = new Date();
    return d.getHours() + " " + d.getMinutes();
}

//Ermittelt den aktuellen Tag.
function GetDay()
{
    var d = new Date();
    var weekday = new Array(7);
    weekday[0]=  "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";
    return weekday[d.getDay()];
}


even the originial doesn't work. I did the things you recommended, but still no function. 
If I try it, there are two different beep signals. The second comes directly after the first one.

Alan Hendry

unread,
Apr 28, 2020, 8:18:46 AM4/28/20
to DroidScript
Tse,
If the index of still isn't working ...
Can you log the string?
It may have different capitals/case.
Regards, Alan H
Reply all
Reply to author
Forward
0 new messages