Cognitive-services-speech-sdk: Support audio level on Android??

Created on 20 Jun 2020  路  3Comments  路  Source: Azure-Samples/cognitive-services-speech-sdk

Is your feature request related to a problem? Please describe.
When user start to speak, I want to do some animation which depends on the audio level of mic input.
When user speak louder o r lower, the animation will be different, maybe a simple wave

Describe the solution you'd like
I think it is not difficult to calculate the audio level during recording, maybe something like:

for (int i = 0; i < buffer.length; i++) {
     v += buffer[i] * buffer[i];
}
double mean = v / (double) r;
double volume = 10 * Math.log10(mean);

Then application can add listener to the event like:

speechRecognizer.volume.addEventListener( (o, event) => { event.audioLevel })

Is it possible?
Thanks a lot.

Most helpful comment

@jzhw0130 Currently SDK does not support this, but you may achieve the functionality if you use external microphone steam e.g. as in sample: https://github.com/microsoft/botframework-solutions/blob/master/samples/android/clients/VirtualAssistantClient/directlinespeech/src/main/java/com/microsoft/bot/builder/solutions/directlinespeech/MicrophoneStream.java
and then you do mic audio level visualization in your app side.

Also look at following sample which does the same in Unity side
https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/unity/from-unitymicrophone/Assets/Scripts/HelloWorld.cs

In the future releases we are adding capability to stream audio back from the speech sdk, which enables you the same. I am closing this, let us know if more information is required

All 3 comments

@jhakulin can you please comment on @jzhw0130 's question?

@jzhw0130 Currently SDK does not support this, but you may achieve the functionality if you use external microphone steam e.g. as in sample: https://github.com/microsoft/botframework-solutions/blob/master/samples/android/clients/VirtualAssistantClient/directlinespeech/src/main/java/com/microsoft/bot/builder/solutions/directlinespeech/MicrophoneStream.java
and then you do mic audio level visualization in your app side.

Also look at following sample which does the same in Unity side
https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/unity/from-unitymicrophone/Assets/Scripts/HelloWorld.cs

In the future releases we are adding capability to stream audio back from the speech sdk, which enables you the same. I am closing this, let us know if more information is required

@oscholz @jhakulin
cool.
Thanks for you guys.
Works perfectly.

Was this page helpful?
0 / 5 - 0 ratings