react-native-vosk icon indicating copy to clipboard operation
react-native-vosk copied to clipboard

Unable to control volume on iOS when vosk is active.

Open pedrolmsin opened this issue 9 months ago • 10 comments

Hello, I'm using the react-native-vosk library for speech recognition in my app, the recognition is used to detect sentences in a text to trigger some actions, on android everything works perfect, but on iOS I'm having some trouble, for example the volume control on iOS is disabled when speech recognition is active, I would like to know if anyone knows how I can enable volume control when speech recognition is active.

I know that this isn't necessarily an issue in the library, but I haven't found anywhere appropriate to ask for help and I don't know how to solve this "issue".

pedrolmsin avatar Mar 03 '25 19:03 pedrolmsin

Hi @pedrolmsin

I think there is code in Swift that temporarily reduces the volume of other audios.

If I'm not mistaken, it would be .duckOthers, from here:

try audioSession.setCategory(.record, mode: .measurement, options: .duckOthers)

Maybe if you pass the options like:

try audioSession.setCategory(.record, mode: .measurement, options: [])

I haven't tested this, but I can test it later and get back to you.

joaolobao380 avatar Mar 07 '25 00:03 joaolobao380

Hi @pedrolmsin

I think there is code in Swift that temporarily reduces the volume of other audios.

If I'm not mistaken, it would be .duckOthers, from here:

try audioSession.setCategory(.record, mode: .measurement, options: .duckOthers)

Maybe if you pass the options like:

try audioSession.setCategory(.record, mode: .measurement, options: [])

I haven't tested this, but I can test it later and get back to you.

I will look into it but any help would be amazing, I have been stuck in this issue for weeks so far, it is the only thing getting in the way of me launching my app, lol, on android it works perfectly but on iOS this library is giving me headaches.

pedrolmsin avatar Mar 07 '25 01:03 pedrolmsin

Hi @pedrolmsin I think there is code in Swift that temporarily reduces the volume of other audios. If I'm not mistaken, it would be .duckOthers, from here: try audioSession.setCategory(.record, mode: .measurement, options: .duckOthers) Maybe if you pass the options like: try audioSession.setCategory(.record, mode: .measurement, options: []) I haven't tested this, but I can test it later and get back to you.

I will look into it but any help would be amazing, I have been stuck in this issue for weeks so far, it is the only thing getting in the way of me launching my app, lol, on android it works perfectly but on iOS this library is giving me headaches.

Later I will try to simulate and solve this problem, I will get back to you here.

joaolobao380 avatar Mar 07 '25 01:03 joaolobao380

Ducking has been removed, can you try again now @pedrolmsin ?

riderodd avatar Mar 31 '25 11:03 riderodd

Ducking has been removed, can you try again now @pedrolmsin ?

Hi, I did some tests and now I can control the volume on iOS after stopping vosk, however when the recognition is active it is still not possible to control the volume of the device, I have to stop the recognition to adjust the volume and then start the recognition again, it improved a little with this new addition, before not even after stopping I could adjust the volume on iOS, but the ideal would be to be able to control the volume even with the voice recognition active, if it is possible to implement this it would be nice, thanks for your attention and time.

pedrolmsin avatar Mar 31 '25 17:03 pedrolmsin

@pedrolmsin Are you unable to control the volume or the audio does not play?

joaolobao380 avatar Apr 09 '25 16:04 joaolobao380

@pedrolmsin Are you unable to control the volume or the audio does not play?

I can't control the volume, when speech recognition is active I can't control the volume on iOS, my application requires speech recognition to be active all the time to recognize certain phrases and play some sounds based on those phrases, I would like to be able to control the volume while recognition is active, on Android this is possible and works perfectly, but on iOS I have to stop speech recognition to allow the user to control the volume, and this becomes unfeasible for the proposal of my application.

pedrolmsin avatar Apr 09 '25 16:04 pedrolmsin

What lib are you using to play the audios? @pedrolmsin

joaolobao380 avatar Apr 09 '25 17:04 joaolobao380

What lib are you using to play the audios? @pedrolmsin

@react-native-community/audio-toolkit

pedrolmsin avatar Apr 09 '25 17:04 pedrolmsin

@pedrolmsin I'm going to do the tests here, because last time I tried to run vosk with @react-native-community/audio-toolkit it didn't work, I had to stop react-native-vosk for it to work

joaolobao380 avatar Apr 11 '25 17:04 joaolobao380

I finally managed to control the audio volume on iOS while voice recognition is active. It might not work for all purposes, but it worked for mine.

try audioSession.setCategory(.playAndRecord, mode: .measurement, options: [.mixWithOthers, .defaultToSpeaker])

pedrolmsin avatar Jun 02 '25 19:06 pedrolmsin