Sounds from a DB?

SandroB4A

Member
Licensed User
Longtime User
Hi to all,
I've spent hours and hours to find a post talking about this without results:BangHead:.

In my app I need sometimes to record the user voice, to save the message somewhere in the device and then in a second moment to play this message.

Now I can save a wav file with Audioecorder and I can play it with Mediaplayer...BUT my app use a sql DB so I'd like to store the messages in it keeping all the data in the same place.

The 1st step I did was to create a temporary wav file and load it as blob in my DB (no way to record sounds as byte on the fly right?).

Now I want to play the data saved in the blob column of my DB, I think I must use a temporary file again, but how do I create a wav file from a DB?

I've found this example:

B4X:
Sub ReadBlob
    Dim Cursor1 As Cursor
    'Using ExecQuery2 is safer as it escapes special characters automatically.
    'In this case it doesn't really matter.
    Cursor1 = SQL1.ExecQuery2("SELECT image FROM table2 WHERE name = ?", Array As String("smiley"))
    Cursor1.Position = 0
    Dim Buffer() As Byte 'declare an empty byte array
    Buffer = Cursor1.GetBlob("image")
    Dim InputStream1 As InputStream
    InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
    
    Dim Bitmap1 As Bitmap
    Bitmap1.Initialize2(InputStream1)
    InputStream1.Close
    Activity.SetBackgroundImage(Bitmap1)
End Sub


but I don't know how to create a wav file after InputStream1.InitializeFromBytesArray instruction.

I stopped one meter before the arrival, please help me to finish my race!:sign0085:

Thanks
 

stevel05

Expert
Licensed User
Longtime User
Have a look at the audio record and audio track libraries. You can get a data in bytes or shorts depending on the quality,and play them back without creating a wav file.

I've not tried storing them in a database, though it should be possible.

via Tapatalk
 
Upvote 0

SandroB4A

Member
Licensed User
Longtime User
@stevel05 Thanks for your reply!, can you suggest me some example on how I can get a data in bytes and play them back without creating a wav file? :sign0104:

@Erel: the new KeyValueStore class seem to be easy and usefull! but I should re-write a big part of the code and, onestly, I wish to complete this my 1st app asap. A question, I still don't understand if it's possible or not to create a wave file from a blob. If yes can you show me an example?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Hi SandroB4a,

The Audio record library has a ReadBytes method which you can store by appending to a bytes array. You can then use bytestostring to convert to a string, although as Erel says, you can store the bytes array to a blob so that should be unnecessary.

The example programs in the first post of the library thread, and later in the thread should give you some pointers.
 
Upvote 0

SandroB4A

Member
Licensed User
Longtime User
Hi SandroB4a,

The Audio record library has a ReadBytes method which you can store by appending to a bytes array. You can then use bytestostring to convert to a string, although as Erel says, you can store the bytes array to a blob so that should be unnecessary.

The example programs in the first post of the library thread, and later in the thread should give you some pointers.

Ok I'll take a look at the Audiorecord post, thanks again.
 
Upvote 0
Top