voice icon indicating copy to clipboard operation
voice copied to clipboard

Conflict between microphone and speaker on the IOS device.

Open igor-martucelli opened this issue 8 years ago • 13 comments

In IOS when permission is granted to the microphone, the device's audio goes to the upper speaker and the sound becomes low because that speaker serves for the purpose of call. Please, anybody can help me?

igor-martucelli avatar Feb 26 '18 12:02 igor-martucelli

@igor-nm @wenkesj I am seeing this as well. When playing audio, and including Voice, the phone ear speaker is used instead of the body speakers. I don't think this was happening a couple weeks ago. I think there might have been a ios change. Any ideas?

dalinarkholin avatar Mar 01 '18 19:03 dalinarkholin

@wenkesj

@ohtangza Pulling you in here since I have seen you active in other issues.

Any idea what is going on here? Check out this thread for a little more context: https://github.com/ak1394/react-native-tts/issues/61

Right now I am trying to figure out how I can just destroy / undo everything a Voice.start()does (after I am done with it) in order to have the case speakers used again instead of the ear speaker.

I have noticed a couple things while tinkering. Right now no matter what I do, I always get a 203 retrywhen calling the destroy method. I am pretty sure this is a error coming from [self.recognitionTask cancel] in teardown.

However even if I remove

[self.recognitionRequest endAudio];   
[self.recognitionTask cancel];

from the teardown method (which gets rid of the 203) I still am seeing the audio move to the ear speaker.

I should clarify further. Audio comes out of the case speakers up until the point Voice.start() is called. Not sure if that is a IOS bug or an issue with this library. In either case. I think the destroy method should literally destroy everything that Voice.start() did.

Could use some help on this. I don't really use Objective C much.

dalinarkholin avatar Mar 02 '18 18:03 dalinarkholin

@dalinarkholin I see this is a problem.

That endAudio method should be invoked to stop adding to the underlying buffer, before calling cancel on the task to avoid overflow (which is most definitely causing an error, somewhere).

I believe the underlying problem may be due to the AVAudioSession in the tts module.

From what I can tell, this particular use-case, session setCategory:AVAudioSessionCategoryPlayback will cause issues when attempting to record on a session that is trying to playback.

This seems to be the root of the problem and explains it pretty throughly. The question is iOS related and would probably involve fixing on the tts end.

wenkesj avatar Mar 02 '18 18:03 wenkesj

Hi guys, everything fine? I would like to thank you guys for looking at this problem, do you guys think we can find a solution to this, or is it really an iOS problem? I do ever not developing in Objective-C so I can not help them much with this. Sorry me. :(

igor-martucelli avatar Mar 07 '18 12:03 igor-martucelli

@wenkesj Thanks for taking a look.

I ended up forking both this module and the react-native-tts module. There were changes needed on both ends. Basically I just switch the AVAudioSession Category and mode on start of both modules. That seemed to at least solve the issue of getting audio back to the case speakers.

dalinarkholin avatar Mar 07 '18 14:03 dalinarkholin

Hello guys, everyone ok? The solution of @dalinarkholin is successfully. I going mark this topical as resolved. I would like to ask you @dalinarkholin to make a pull request with this project, and too for project react-native-tts, so that help everyone of in the community.

igor-martucelli avatar Mar 13 '18 20:03 igor-martucelli

@wenkesj @ak1394

I'll leave it up to you guys to debate on this. I have done little testing and am not confident enough to say that nothing broke.

dalinarkholin avatar Mar 20 '18 20:03 dalinarkholin

Hi guays, news on this subject? Do you think there is a better way to solve the problem? @wenkesj @ak1394 @dalinarkholin

igor-martucelli avatar Apr 02 '18 12:04 igor-martucelli

@wenkesj I was able to simplify my solution by handling the change of AVSession mode / category in teardown of this module.

dalinarkholin avatar Apr 02 '18 13:04 dalinarkholin

guys what was the solution here? it seems that this bug is still exists

idan6189 avatar Nov 27 '18 12:11 idan6189

use master, it should be fixed

sibelius avatar Nov 27 '18 12:11 sibelius

Some issue. @idan6189 does it works?

under94 avatar Dec 04 '18 19:12 under94

use this when initialising audiosession
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error: nil]; this solved the issue for me

dheeraj-iitd avatar Feb 05 '19 13:02 dheeraj-iitd