Audio Voice Recorder
How to make a audio Voice Recorder in DroidScript?
Audio Player made in Script Language of DroidScript in very Easy with short codes. I give you an example but completely different in various method. buy the way, codes are never used in any program or app before I send it to my web post.
Thanks you for all Reader's.
Audio Player with Recorder version 3.0
Coding Start here ...
//Create global variables.
cnfig="cnfig.txt";
var FileNum=0;
var destFile =0
var timer =0;
var Tim=0;
var sec=0;
var hrs=0;
var min=0;
var dur,prog;
//Called when application is started.
function OnStart()
{
app.MakeFolder("/sdcard/AudioRecord/" )
app.LoadNumber("FileNum",0,cnfig)
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" )
lay.SetBackColor( "#ffffcc" )
layBut= app.CreateLayout( "linear", "Horizontal,FillX" )
layBut.SetBackColor( "#000001" )
layBut2= app.CreateLayout( "linear", "Horizontal,FillX" )
layBut2.SetBackColor( "#f3ff11" )
layBott= app.CreateLayout( "linear", "VCenter,FillX" )
layBott.SetBackColor( "#11ff11" )
//Header text
txtHead = app.CreateText( hrs+":"+min+":"+sec, 0.8 )
txtHead.SetTextColor( "#3fff0e")
txtHead.SetTextShadow( 1, 0,1, "#88ffffff" )
txtHead.SetTextSize( 24 )
lay.AddChild( txtHead )
txtHead2= app.CreateText( "Recording Duration", 0.8 )
txtHead2.SetTextColor( "#3fff0e")
txtHead2.SetTextShadow( 1, 0,1, "#88ffffff" )
txtHead2.SetTextSize( 24 )
lay.AddChild( txtHead2 )
//the other to draw the graph background and data.
layGraph = app.CreateLayout( "Frame" )
lay.AddChild( layGraph )
imgBack = app.CreateImage( null, 0.95, 0.2 )
imgBack.SetAutoUpdate( false )
layGraph.AddChild( imgBack )
imgData = app.CreateImage( null, 0.95, 0.2 )
imgData.SetAutoUpdate( false )
layGraph.AddChild( imgData )
//Create a text control for Recording to show data log.
txt = app.CreateText( "Level: 0%", 0.8 )
txt.SetTextColor( "#3f638e")
txt.SetTextShadow( 1, 0,1, "#88ffffff" )
txt.SetTextSize( 24 )
lay.AddChild( txt )
ttp2 =app.CreateText( "" )
ttp2.SetTextColor( "#ff3300" )
layBott.AddChild( ttp2 )
//Create a 'Start Recordind' button.
btnStart = app.CreateImage(null, 0.4,0.2,"Button")
btnStart.SetPaintColor( "#660055" )
btnStart.DrawCircle( 0.5,0.5,0.40)
btnStart.SetPaintColor( "#f00055" )
btnStart.SetTextSize( 16)
btnStart.DrawText("Record",0.3,0.5 )
btnStart.SetOnTouchUp( btnStart_OnTouch )
lay.AddChild( btnStart )
//Create a 'Pause Recording' button.
btnPause = app.CreateButton( "[fa-pause]", 0.2, -1, "FontAwesome,NoSound" )
btnPause.SetBackColor( "#f00055" )
btnPause.SetOnTouch( btnPause_OnTouch )
layBut2.AddChild( btnPause )
//Create a 'Stop Recording' button.
btnStop = app.CreateButton( "[fa-stop]", 0.2, -1, "FontAwesome,NoSound" )
btnStop.SetBackColor( "#f00055" )
btnStop.SetOnTouch( btnStop_OnTouch )
layBut2.AddChild( btnStop )
//ooooooooooooooooooEND Recording buttons.
//Create a 'Stop' button.
btnStp = app.CreateButton( "[fa-stop]", 0.2, -1, "FontAwesome,Alum,NoSound" )
btnStp.SetOnTouch( btnStp_OnTouch )
layBut.AddChild( btnStp )
//Create a 'pause' button.
btnPaus = app.CreateButton( "[fa-pause]", 0.2, -1, "FontAwesome,Alum,NoSound" )
btnPaus.SetOnTouch( btnPaus_OnTouch )
layBut.AddChild( btnPaus)
//Create a 'Play' button.
btnPlay = app.CreateButton( "[fa-play]", 0.2, -1, "FontAwesome,Alum,NoSound" )
btnPlay.SetOnTouch( btnPlay_OnTouch )
layBut.AddChild( btnPlay )
//Create a 'File Open' button.
btnOpen = app.CreateButton( "[fa-file]", 0.2, -1, "FontAwesome,Alum,NoSound" )
btnOpen.SetOnTouch( btnOpen_OnTouch )
layBut.AddChild( btnOpen )
//Create seek bar and add to layout.
skb = app.CreateSeekBar(0.9, -1 )
skb.SetMargins( 0, 0.05, 0, 0)
skb.SetRange( 1.0)
skb.SetOnTouch( skb_OnTouch )
layBott.AddChild( skb )
txtDur=app.CreateText( "")
layBott.AddChild( txtDur )
//duration time in seconds
ttp=app.CreateText( "0.00",0.2,-1 )
layBott.AddChild( ttp )
//Add layout to app.
lay.AddChild( layBut2 )
lay.AddChild( layBott )
app.AddLayout( lay )
lay.AddChild( layBut )
rec = app.CreateAudioRecorder()
//Create media player.
player = app.CreateMediaPlayer()
player.SetFile( destFile )
player.SetOnReady( player_OnReady )
//Switch off debug so we don't fill the log.
app.SetDebugEnabled( false )
rec.SetFrequency( 20000 )
//Draw our sample graph background.
DrawGraph();
//Start timer to update seek bar every second.
setInterval( "Update2()", 100 )
}
//Called when user touches our 'Start' button.
function btnStart_OnTouch()
{
Tim=0;
sec=0;
min=0;
hrs=0;
txtHead.Show()
//Create Audio Recorder and set dest file.
destFile= "/sdcard/AudioRecord/AudioRec0"+FileNum+".wav";
rec.SetFile( destFile )
rec.Start()
txt.SetTextColor( "#aa2222" )
clearInterval( timer )
timer = setInterval( GetLevel, 250 )
timer = setInterval( GetSamples, 10 )
app.SaveNumber( "FileNumber" ,++FileNum,cnfig)
setInterval("Time()",1000)
}
//Called when user touches our 'Pause' button.
function btnPause_OnTouch()
{
rec.Pause()
txt.SetTextColor( "#aa2222" )
}
//Called when user touches our 'Stop' button.
function btnStop_OnTouch()
{
rec.Stop()
txt.SetTextColor( "#aa2222" )
txt.SetText( "Level: 0%" )
clearInterval( timer )
txtHead.Gone();
}
function btnStp_OnTouch()
{
player.Stop()
}
function GetLevel()
{
var level = rec.GetRMS()
txt.SetText( "Level: " + Math.round(100*level/0.72) + "%" )
}
//Called when
function btnPlay_OnTouch()
{
player.Play();
}
function btnPaus_OnTouch()
{
player.Pause();
}
//Called when the WAV file is loaded.
function player_OnReady()
{
}
function skb_OnTouch(value)
{
player.SeekTo(dur*value);
}
//Update seek bar.
function Update2()
{
dur =player.GetDuration()
prog =player.GetPosition();
if (dur){ skb.SetValue( prog/dur);
ttp.SetText(prog);
txtDur.SetText( dur )
}
}
//Get samples from the current data buffer.
function GetSamples()
{
var data = rec.GetData()
DisplaySamples( data )
}
//Draw graph display background.
function DrawGraph()
{
//Fill image with solid black.
imgBack.SetColor( "#ff000000" )
//Set drawing color to blue.
//format is (#alpha:red:green:blue) in hex.
imgBack.SetPaintColor( "#ff4224ff" )
//Draw x and y axis.
imgBack.SetLineWidth( 4.0 )
imgBack.DrawLine( 0, 1.0, 1.0, 1.0 )
imgBack.DrawLine( 0, 0, 0, 1.0 )
//Horizontal lines.
imgBack.SetLineWidth( 0.5 )
imgBack.DrawLine( 0, 0.25, 1.0, 0.25 )
imgBack.SetLineWidth( 1.0 )
imgBack.DrawLine( 0, 0.5, 1.0, 0.5 )
imgBack.SetLineWidth( 0.5 )
imgBack.DrawLine( 0, 0.75, 1.0, 0.75 )
//Draw top and right lines.
imgBack.SetLineWidth( 4.0 )
imgBack.DrawLine( 0, 0, 1.0, 0 )
imgBack.DrawLine( 1.0, 0, 1.0, 1.0 )
//Change paint color and line width.
imgBack.SetLineWidth( 1.0 )
imgBack.SetPaintColor( "#ff44ff44" )
//Update the background image.
imgBack.Update()
//Set properties for forground image (sample data).
imgData.SetLineWidth( 1.0 )
imgData.SetPaintColor( "#ff4444ff" )
}
//Display audio samples on graph.
function DisplaySamples( data )
{
imgData.SetColor( "#00000000" )
//Draw samples
imgData.DrawSamples( data, 32768 )
/* Alternative (slower) drawing method.
var y = lasty = 0.5;
var x = lastx = 0;
var len = data.length;
for( var i=0; i=60)
{
Tim=0;
sec=0;
min++;
txtHead.SetText( hrs+":"+min+":"+sec, 0.8)
}
if (min>=60)
{
hrs++;
txtHead.SetText( hrs+":"+min+":"+sec, 0.8 )
min=0;}
}
0 Comments