Forum Archive

Speech to ear speaker?

dwildbore

Is there away to use the text to speak so that it outputs to the ear speaker and not the speaker phone?

Phuket2

@dwildbore , hi I used the example below from the Pythonista docs. I am using apple Airpods on iPad 12.5' 2nd gen. The sound worked fine for me. When the AirPods in, the speech came though them and after removal the sound come out of the speaker. I didn't have a wired pair of earphones handy to see if it worked differently or not.

import speech
import time

def finish_speaking():
    # Block until speech synthesis has finished
    while speech.is_speaking():
        time.sleep(0.1)

# US English:
speech.say('Hello World', 'en_US')
finish_speaking()
# Spanish:
speech.say('Hola mundo', 'es_ES')
finish_speaking()
# German:
speech.say('Hallo Welt', 'de_DE')
finish_speaking()
dwildbore

I should have clarified. I mean like the speaker used during a phone call that you hold up to your ear. Good to know the ear pods work tho, i'm hoping to get a pair! thanks!

dwildbore

In case anyone is wondering I got it working:

from objc_util import *
import speech
import time

AVAudioSession = ObjCClass('AVAudioSession')
audioSession = AVAudioSession.sharedInstance()

oldCategory = audioSession.category()

audioSession.setCategory_error_(ns('AVAudioSessionCategoryPlayAndRecord'), None)

speech.say('hello') #like a phone call

time.sleep(1)
audioSession.setCategory_error_(ns(oldCategory), None)

speech.say('hello again') # speaker phone