Select audio from external storage corona sdk - audio

I have to select audio file from device storage.it is possible in corona SDK.Any other solution for this scenario.

I have something like this that works fine ans shows me all the lines in that file:
log = "/sdcard/coordinates1.txt" -- sdcard
function listfiles ()
local doc_path = system.pathForFile( log)
i=1
for file in lfs.dir(doc_path) do
i = i+1
ycort = display.newText ( file, 80, 280+i*10, native.systemFont, 12)
end
end

Related

How to download a sentinel images from google earth engine using python API in tfrecord

While trying to download sentinel image for a specific location, the tif file is generated by default in drive but its not readable by openCV or PIL.Image().Below is the code for the same. If I use the file format as tfrecord. There are no Images downloaded in the drive.
starting_time = '2018-12-15'
delta = 15
L = -96.98
B = 28.78
R = -97.02
T = 28.74
cordinates = [L,B,R,T]
my_scale = 30
fname = 'sinton_texas_30'
llx = cordinates[0]
lly = cordinates[1]
urx = cordinates[2]
ury = cordinates[3]
geometry = [[llx,lly], [llx,ury], [urx,ury], [urx,lly]]
tstart = datetime.datetime.strptime(starting_time, '%Y-%m-%d') tend =
tstart+datetime.timedelta(days=delta)
collSent = ee.ImageCollection('COPERNICUS/S2').filterDate(str(tstart).split('')[0], str(tend).split(' ')[0]).filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20)).map(mask2clouds)
medianSent = ee.Image(collSent.reduce(ee.Reducer.median())) cropLand = ee.ImageCollection('USDA/NASS/CDL').filterDate('2017-01-01','2017-12-31').first()
task_config = {
'scale': my_scale,
'region': geometry,
'fileFormat':'TFRecord'
}
f1 = medianSent.select(['B1_median','B2_median','B3_median'])
taskSent = ee.batch.Export.image(f1,fname+"_Sent",task_config)
taskSent.start()
I expect the output to be readable in python so I can covert into numpy. In case of file format 'tfrecord', I expect the file to be downloaded in my drive.
I think you should think about the following things:
File format
If you want to open your file with PIL or OpenCV, and not with TensorFlow, you would rather use GeoTIFF. Try with this format and see if things are improved.
Saving to drive
Normally saving to your Drive is the default behavior. However, you can try to force writing to your drive:
ee.batch.Export.image.toDrive(image=f1, ...)
You can further try to setup a folder, where the images should be sent to:
ee.batch.Export.image.toDrive(image=f1, folder='foo', ...)
In addition, the Export data help page and this tutorial are good starting points for further research.

save file from url lua ubuntu

I want download mp3 file from UTL and save it to a folder.
This is my code:
local sound = HTTPS.request('https://hozory.com/translate/?target='..matches[1]..'&text='..text)
local voice = json:decode(sound)
if voice.result.Voice_link ~= "false" then
local f = assert(io.open('test.mp3', 'w'))
f:write(voice.result.Voice_link)
f:close()
But this creates an empty mp3 file.

Can I use an ended sound file to transition to a new scene or refresh data in the same scene?

Lua novice asks:
How do I transition from this...
(a simple example to establish a how-to)...
visual = display.newImage( "redCircle.png", 50, 50 )
local music = audio.loadStream("sound1.mp3")
audio.play(music)
audio.stopWithDelay(60000/60)
to this, timed by the first sound file ending?
visual = display.newImage( "blueCircle.png", 50, 50 )
local music = audio.loadStream("sound2.mp3")
audio.play(music)
audio.stopWithDelay(60000/60)
Which api should I be experimenting with? I've looked at https://docs.coronalabs.com/api/index.html
What am I missing?
What you can do is create a function listener for the first audio file you can look more here: https://docs.coronalabs.com/api/library/audio/play.html Below is a sample code I can give you. Note that I did not use audio.stopWithDelay
--DECLARE LOCAL VARIABLES
local visual1
local visual2
local music1
local music2
--LOAD SOUNDS
music1 = audio.loadStream("sound1.mp3")
music2 = audio.loadStream("sound2.mp3")
local function soundIsFinished(event)
if (event.completed) then
--PLAY SECOND AUDIO AND HIDE/REMOVE VISUAL 1
visual1.isVisible = false
visual2.isVisible = true
audio.play(music2, {duration = 1000})
end
end
--DISPLAY VISUAL1 and play MUSIC1
visual1 = display.newImage("redCircle.png", 50,50)
--AUDIO WILL PLAY FOR 1 SECOND (60000/60) is 1 second
audio.play(music1, { duration=1000, onComplete=soundIsFinshed } )
-- HIDE VISUAL2 FIRST
visual2 = display.newImage("blueCircle.png", 50,50)
visual2.isVisible = false
Hope This helps.

Only one image getting uploaded multiple times

I have been using mechanize gem to scrape data from craigslist, I have a piece of code that uploads multiple image to craigslist, all the file paths are correct, but only single image gets uploaded multiple times what's the reason.
unless pic_url_arry.blank?
unless page.links_with(:text => 'Use classic image uploader').first.blank?
page = page.links_with(:text => 'Use classic image uploader').first.click
end
puts "After classic image uploader"
form = page.form_with(class: "add")
# build full file path before setting like this => file = File.join( APP_ROOT, 'tmp', 'image.jpg')
i = 0
pic_url_arry = pic_url_arry.shuffle
pic_url_arry.each do |p|
form.file_uploads.first.file_name = p
i+= 1
page = form.submit
puts "******#{p.inspect}*******"
puts "******#{page.inspect}*******"
end unless pic_url_arry.blank?
# check if the file uploaded sucessfully with no. of files with no. of imgbox on page.
check_image_uploaded = page.at('figure.imgbox').count
if check_image_uploaded.to_i == i.to_i
# upload failure craiglist or net error.
end
end
AND the pic array has value as ["/home/codebajra/www/office/autocraig/public/uploads/posting_pic/pic/1/images__4_.jpg", "/home/codebajra/www/office/autocraig/public/uploads/posting_pic/pic/2/mona200.jpg", "/home/codebajra/www/office/autocraig/public/uploads/posting_pic/pic/3/images__1_.jpg"].
The form holding filefield is being set only once, which is taking only one image that hits first. So, the updated code will be,
unless pic_url_arry.blank?
unless page.links_with(:text => 'Use classic image uploader').first.blank?
page = page.links_with(:text => 'Use classic image uploader').first.click
end
puts "After classic image uploader"
form = page.form_with(class: "add")
# build full file path before setting like this => file = File.join( APP_ROOT, 'tmp', 'image.jpg')
i = 0
pic_url_arry = pic_url_arry.shuffle
pic_url_arry.each do |p|
form.file_uploads.first.file_name = p
i+= 1
page = form.submit
form = page.form_with(class: "add")
puts "******#{p.inspect}*******"
puts "******#{page.inspect}*******"
end unless pic_url_arry.blank?
# check if the file uploaded sucessfully with no. of files with no. of imgbox on page.
check_image_uploaded = page.at('figure.imgbox').count
if check_image_uploaded.to_i == i.to_i
# upload failure craiglist or net error.
end
end
hoping this will solve the problem.

Play Raw File Using NAudio Library

Hello i have following code to play raw file.my raw file duration is 25 second. this code is working fine but after sometime my program play raw file very slow almost 50% speed and my raw file duration is increase 36 second when i restart my pc and run my program its working normaly again. i need to restart my pc every one hour to work correctly please check what is wrong with my code here is my code
Try
Dim rawStream = File.OpenRead("C:\myFile.raw")
Dim waveFormat = New NAudio.Wave.WaveFormat(8000, 16, 1)
Dim rawSource = New RawSourceWaveStream(rawStream, waveFormat)
Dim audioBufferSize = 320
Dim offset As Integer = 0
Dim buffer As Byte() = New Byte(audioBufferSize - 1) {}
Dim buffer2 As Byte() = New Byte(320) {}
While (rawSource.Read(buffer2, offset, audioBufferSize) > 0)
msport.Write(buffer2, offset, audioBufferSize)
Thread.Sleep(20)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
NAudio is not having any effect at all in your code sample. All you are doing is reading data from a file, and sending it to the serial port. RawSourceWaveStream simply attaches a WaveFormat to the file stream, but nothing is reading that stream. Whatever device you have listening to the audio data you're sending over the serial port will have an audio format it is expecting. You need to find out what that is. Then you can use NAudio to convert the audio to the correct format if it is not already at the right sample rate / channel count (which would be the two most likely causes of audio playing at 50% speed)

Resources