gauravk95 / audio-visualizer-android

🎵 [Android Library] A light-weight and easy-to-use Audio Visualizer for Android.
Apache License 2.0
844 stars 127 forks source link

Question: Is this only for already saved audio files? #5

Closed AndroidDeveloperLB closed 5 years ago

AndroidDeveloperLB commented 5 years ago

Or can I use this while recording audio, too?

And why does it need microphone permission on the sample? Doesn't it just use the current sound waves that are played?

gauravk95 commented 5 years ago

It can be used for audio recording too, for that you can use setRawAudioBytes(byte[])

Yes, you guessed it right. Actually, this library is based on Visualizer class in audiofx, and Microphone permissions are required by it. https://developer.android.com/reference/android/media/audiofx/Visualizer

Hope this answers your question!

AndroidDeveloperLB commented 5 years ago

I don't understand. If it's not needed, why request the permission? What is the purpose of the permission, if it already has all the data within the audio file?

Can you please put into the sample of how to make it work with the recorder, as you record and maybe also before you record (meaning when it's idle) ?

gauravk95 commented 5 years ago

The Visualizer class requires the Microphone permissions, as it takes data from the stream playing. This class is provided by the android.media package, and the permission is compulsory for it to work.

You are right when you say data is already available in the audio file. We can also extract the data from the file, do some FFT, normalization and make it work without the permission. But, for that I will have to write a complete custom implementation of extracting the audio data and managing. I went with the Visualizer class to reduce the complexity and the work load, but the library can surely be improved. I just don't have time to do that right now.

Regarding sample, I will get on it ASAP.

AndroidDeveloperLB commented 5 years ago

It's just that a visualizer on audio files can be used on music players, but it's weird to request a microphone permission for this... I tried to make noise while it played, to see if it affected it, as I thought that's why it requested the permission...

So I think that currently, the only usage for this library would usually be of recording apps, though it could be used on such apps in all recording steps (before, during, and while playing).

AndroidDeveloperLB commented 5 years ago

I've also noticed that if I change the volume level to 0, I don't see the visualizer do anything anymore. Is this intentional? Could it be changed?

gauravk95 commented 5 years ago

Nope, it can't be changed, but would be possible using custom implementation. I will see if I can pull some time to implement the custom version of the library.

AndroidDeveloperLB commented 5 years ago

By "custom implementation" , you mean something that will look at the audio data directly, without the need for microphone ?

gauravk95 commented 5 years ago

Yeah correct.

AndroidDeveloperLB commented 5 years ago

Cool. Thank you for your time. I hope you succeed.

christina-bakirtzi commented 2 years ago

Supposing we have a recorder that goes like this:

    try {
        recorder.prepare();
        recorder.start();
    } catch (IOException e) {}

where should we put the setRawAudioBytes(byte[]) to have it display in real-time?