//Create an edit control.
edit = app.CreateTextEdit( "Hello", 1, 0.9, "" );
edit.SetBackColor( "#222222" );
edit.SetTextColor( "#ffffff" );
lay.AddChild( edit );
//Create a horizontal layout for icon buttons.
layBut = app.CreateLayout("Linear", "Horizontal");
lay.AddChild( layBut );
//Create an array of icon buttons.
var btns = ["[fa-undo]","[fa-search]","[fa-file]","[fa-save]","[fa-repeat]"];
for( var i=0; i<btns.length; i++ )
{
btn = app.CreateButton( btns[i], -1, 0.06, "FontAwesome" );
btn.icon = btns[i];
btn.SetTextSize( 22 );
btn.SetOnTouch( btns_OnTouch );
layBut.AddChild( btn );
}
//Add layout to app.
app.AddLayout( lay );
}
//Handle button presses.
function btns_OnTouch()
{
switch( this.icon )
{
case "[fa-undo]": edit.Undo(); break;
case "[fa-repeat]": edit.Redo(); break;
case "[fa-search]": alert("Todo!"); break;
case "[fa-file]":
edit.SetText( app.ReadFile( "/sdcard/testfile.txt" ) );
break;
case "[fa-save]":
app.WriteFile( "/sdcard/testfile.txt", edit.GetText() );
break;
}
}
This is the voice commands sample i was modifying it
//Note: Offline recognition engines can be downloaded in the
//Android Language and Input settings (recommended for speed).
//Higher quality voices may also be downloaded.
//Called when application is started.
function OnStart()
{
//Create a main layout with objects vertically centered.
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 );
//Add layout to app.
app.AddLayout( lay );
//Create recognition object and set callbacks.
speech = app.CreateSpeechRec("NoBeep,Parxtial");
speech.SetOnResult( speech_OnResult );
speech.SetOnError( speech_OnError );
//Say something at start (to get speech engine ready).
app.TextToSpeech( "Your wish is my command", 1, 1.5, Listen );
app.ShowProgress();
}
//Start recognizing.
function Listen()
{
app.HideProgress();
speech.Recognize();
}
//Called with the recognition result(s).
function speech_OnResult( results, partial )
{
//Get result.
var cmd = results[0].toLowerCase();
//Watch for key phrases.
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( "I'm feeling good", 1,2, Listen );
}
else if( cmd.indexOf("exit")>-1 )
{
app.Exit();
}
//Restart recognition.
else speech.Recognize();
}
//Called if recognition fails.
function speech_OnError( error )
{
console.log( "Error" + error );
//Restart recognition.
if( !speech.IsListening() ) speech.Recognize();
}
//Get the current time.
function GetTime()
{
var d = new Date();
return d.getHours() + " " + d.getMinutes();
}
//Get the current day.
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()];
}
This is theright one
app.DisableKeys( 'VOLUME_UP,VOLUME_DOWN' );
app.SetOnKey( OnKeyPressed );function OnKeyPressed( type, name )
{
if( name == "VOLUME_UP" && type == "Up" )
{
var volume = app.GetVolume( 'music' );
volume += 0.1;
app.SetVolume( 'music', volume );
var newVolume = app.GetVolume( 'music' );
app.ShowPopup( 'music volume: ' + newVolume, 'Short' );
}
else if( name == "VOLUME_DOWN" && type == "Up" )
{
var volume = app.GetVolume( 'music' );
volume -= 0.1;
app.SetVolume( 'music', volume );
var newVolume = app.GetVolume( 'music' );
app.ShowPopup( 'music volume: ' + newVolume, 'Short' );
}
else return;
}app.TextToSpeech( "Your wish is my command", 1, 1.5, Loop, 'music' );Have you tried resetting the volume straight after there may gave been a Recognize command?
Something like:
app.SetVolume( "music",1 );
}
//Called with the recognition result(s).
function speech_OnResult( results, partial )
{
//Get result.
var cmd = results[0].toLowerCase();
//Watch for key phrases.
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( "I'm feeling good", 1,2, Listen );
}
else if( cmd.indexOf("exit")>-1 )
{
app.Exit();
}
//Restart recognition.
else speech.Recognize();
app.SetVolume( "music",1 );
}
//Called if recognition fails.
function speech_OnError( error )
{
console.log( "Error" + error );
//Restart recognition.
if( !speech.IsListening() ) speech.Recognize();
app.SetVolume( "music",1 );
//Note: Offline recognition engines can be downloaded in the
//Android Language and Input settings (recommended for speed).
//Higher quality voices may also be downloaded.
//Called when application is started.
function OnStart()
{
app.SetOrientation( 'Portrait' );
app.DisableKeys( 'VOLUME_UP,VOLUME_DOWN' );
app.SetOnKey( OnKeyPressed );
//Create a main layout with objects vertically centered.
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
lay.SetBackground( "/res/drawable/pattern_carbon", "repeat" );
var s = "<u>Commands</u><br><br>"
+ "\"What time is it?\"<br>"
+ "\"What day is it?\"<br>"
+ "\"Play\"<br>"
+ "<br><br><br>"
+ "\"Volume\"<br>"
+ "\"Up\"<br>"
+ "\"Down\"<br>"
+ "\"Exit\"<br>";
txt = app.CreateText( s, 0.9, 0.8, "Multiline,Html" );
txt.SetTextSize( 32 );
lay.AddChild( txt );
//Add layout to app.
app.AddLayout( lay );
//Create recognition object and set callbacks.
speech = app.CreateSpeechRec("NoBeep,Parxtial");
speech.SetOnResult( speech_OnResult );
speech.SetOnError( speech_OnError );
//Say something at start (to get speech engine ready).
app.TextToSpeech( "Your wish is my command", 1, 1.5, Listen, "music" );
app.ShowProgress( 'Init' );
player = app.CreateMediaPlayer();
player.SetFile( '/Sys/Snd/Poing.ogg' );
player.SetOnReady( function() { console.log( 'player is ready' ); } );
}
function OnKeyPressed( type, name )
{
if( name == "VOLUME_UP" && type == "Up" )
{
var volume = app.GetVolume( 'music' );
volume += 0.1;
app.SetVolume( 'music', volume );
var newVolume = app.GetVolume( 'music' );
app.ShowPopup( 'music volume: ' + newVolume, 'Short' );
}
else if( name == "VOLUME_DOWN" && type == "Up" )
{
var volume = app.GetVolume( 'music' );
volume -= 0.1;
app.SetVolume( 'music', volume );
var newVolume = app.GetVolume( 'music' );
app.ShowPopup( 'music volume: ' + newVolume, 'Short' );
}
else return;
}
//Start recognizing.
function Listen()
{
app.ShowProgress( 'Lintening', 'NoDim' );
speech.Recognize();
}
//Called with the recognition result(s).
function speech_OnResult( results, partial )
{
app.HideProgress();
//Get result.
var cmd = results[0].toLowerCase();
console.log( 'Understood: ' + cmd );
//Watch for key phrases.
if( cmd.indexOf("what")>-1 && cmd.indexOf("time")>-1 )
{
app.TextToSpeech( GetTime(), 1,2, Listen, "music" );
}
else if( cmd.indexOf("what")>-1 && cmd.indexOf("day")>-1 )
{
app.TextToSpeech( GetDay(), 1,2, Listen, "music" );
}
else if( cmd.indexOf("play")>-1 )
{
player.SeekTo( 0 );
player.Play();
Listen();
}
else if( cmd.indexOf("volume")>-1 )
{
app.TextToSpeech( app.GetVolume( 'music' ), 1, 2, Listen, 'music' );
}
else if( cmd.indexOf("up")>-1 )
{
app.SetVolume( 'music', app.GetVolume( 'music' ) + 0.1 );
app.TextToSpeech( app.GetVolume( 'music' ), 1, 2, Listen, 'music' );
}
else if( cmd.indexOf("down")>-1 )
{
app.SetVolume( 'music', app.GetVolume( 'music' ) - 0.1 );
app.TextToSpeech( app.GetVolume( 'music' ), 1, 2, Listen, 'music' );
}
else if( cmd.indexOf("exit")>-1 )
{
app.Exit();
}
//Restart recognition.
else
{
app.Alert( 'cmd: ' + cmd, 'Unknown' );
Listen();
}
}
//Called if recognition fails.
function speech_OnError( error )
{
console.log( "Error" + error );
//Restart recognition.
if( !speech.IsListening() ) speech.Recognize();
}
speech = app.CreateSpeechRec("Parxtial"); speech = app.CreateSpeechRec();