How do I save the SoundRecorder component files in numbered order?

Hello Koders, I need help with a problem, how can I save the files of the SoundRecorder component in numbering order?

ex. mySound1, mySound2, mySound3, etc.

In the saved recording block of sound recorder component you need to set the file path which includes file name, so while storing the filename you need to use a variable, which will be initialized globally to empty string, this variable will contain filename. As you want that the name should be in numbering order, in the after sound recorded block of sound recorder component you need to add 1 to a math variable which will be joined to the filename variable…

So in simple words,
After sound recorded
Set math variable to math variable value +1
Set filename variable to name, join math variable
Set save recording block of sound recorder component to file path which includes filename variable

1 Like

You could send an example directly with blocks, because I have not understood well.
I am new to Kodular and am still learning. I would be infinitely grateful to you.

Hi, it is not a good idea to show blocks, if I did so, I would stop you from rectifying errors yourself, and learning different things, so you can try and if you face issues we are here to help

Okay, thank you all the same. Now I try.

I definitely got it all wrong.

initialize your math variable with 0 and increment it by 1 to get the next number
you can find the + block in the Math drawer
then put together the filename using the join block
and first set the filename and then start the soundrecorder, i.e. move all these blocks into the button click event assuming you are using a button to start the soundrecorder

Taifun

I entered all the blocks in the event When SoundRecorder .Stopped Recording" and now sorts them by numbering but a new number is added to each new saved file:

Also you can store the number in tiny db and get it on screen initialize so recording won’t be replaced when reopening the application as it will restart the numbering from 0

Can you post your relevant blocks so we can hep you…Did you make what @Taifun and @Soham_Shah told you…

Sorry to steal all this time, unfortunately I’m trying to learn.

When you record for the first time you set the file name for example to recording1 then you set it the next time to recoding12 as you are joining the file name which you already set…Summary :When you are joining the file name with the math you join the old one as well which is recording1 so it results recording12…

How to solve it?

Put a setter block to set the file name to “Recording” again after setting the save recording property

1 Like
2 Likes
  1. count before starting
  2. add the math vairable into the join to get the final filename and set the property SavedRecording before starting

Taifun

2 Likes

Ok, the files are saved and sorted correctly with numbering … when the app is restarted, when I start a new recording, the old files are replaced with the new ones. For this problem I can insert a TinyDB, right? Thank you all for the help you have given me and for your patience. :sweat_smile:

Right You can see my comment :

1 Like

Hi everyone, I’m Ragnarok , I created a new account and this old one is in the process of being deleted. I noticed a small problem with the recorder: When I go to delete a recording and create a new one, the latter instead of replacing the deleted one, continues the numbering order … it is possible to create a sort of “mechanism” to solve the problem?

Example:

Recording1
Recording2 (file deleted or renamed)

The next registration is Recording3 but, since Recording2 has been deleted or renamed by the user, Recording3 will become Recording2 and after which the numbering order will be resumed (Recording4, Recording5 etc.)

1 Like

That could be implemented…
Try this:


That is a for loop that will check if all of the files that is recorded by the application is exists ( not deleted )…If it exists it will set the OldFileFound to false…Else it will set it to true…Set saved recording to sound{number} so if a file deleted it will be replaced and break the loop…When the loop end it will check if OldFileFound is equal to false…If its equal to false it will save the file to the new name…And increase the global number variable by 1…
Don’t forget to change the path in exists block to your file pathes…
Eg.:
If we have recording 1 and 2 and 3…
If i deleted recording1…If you created a new recording its will be 1…Then the next time the number will be 4 ( to complete the order )…

2 Likes

I will first initialize a local variable = 0, then inside use while test file exist, add 1 to a variable. After while test, save recording using the local variable

1 Like

Your way has only one problem…If two sounds are recorded they will be with the same name…Any way its better that it will work without tiny dbd which can be removed in any time by clearing cache…

1 Like