Forum Archive

record sound but cant replay it in speaker

easy_fly
import sound
import dialogs

recorder = sound.Recorder('speech.m4a')
#recorder.record()

dialogs.alert('Recording...', '',   'Finish', hide_cancel_button=True)

#recorder.stop()

p=sound.Player('speech.m4a')
p.play()


When I comment that record code, the sound came out from the speaker.

but when i use the record code,the player sound come from the headphone.

how can i record sound and replay it in speaker at once?

thx

leochai

I had same problem with you.

i think there’s a bug about mute switch when recording.

anyway if you do like this, you can play sound in speaker again.

sound.set_honors_silent_switch(False)

Potomok

I think OMZ should add a method to sound module to control the audio routing. For now you can use objective-c calls after recording / before playing:

import objc_util

au = objc_util.ObjCClass("AVAudioSession").sharedInstance()

# force playback on speaker
au.setCategory_withOptions_error_("AVAudioSessionCategoryPlayback",1,None)