I'm experimenting with Airfoil and the plug-in to get speech to text announcements going for my security system. The script below works, but with some caveats:
- Code: Select all
#!/usr/local/bin/indigo-host -x
from AppKit import NSSpeechSynthesizer
import time
studyHomePodID = 86734491
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
result = airfoilPlugin.executeAction("connect", deviceId=studyHomePodID, waitUntilDone=True) # ID of Speaker device
time.sleep(1.0) # Required or else audio comes through Mac speaker
text = "Hi"
nssp = NSSpeechSynthesizer
ve = nssp.alloc().init()
ve.setVoice_("com.apple.speech.synthesis.voice.samantha")
ve.startSpeakingString_(text)
while not ve.isSpeaking():
time.sleep(0.1)
while ve.isSpeaking():
time.sleep(0.1)
time.sleep(2.0) # Required or else no audio
result = airfoilPlugin.executeAction("disconnect", deviceId=studyHomePodID, waitUntilDone=True) # ID of Speaker device
Note the two comments starting with 'Required or else'. It appears I need to force some delays in the code in order for the audio to propagate out to the HomePod speaker that I'm trying to play audio to.
Is this normal? I noticed the 'waitUntilDone' parameter of the executeAction is set to True, but delays are still necessary.
Just wondering if this is expected.