iTunes Pause and Speak

Posted on
Sat Jan 07, 2012 2:06 pm
jehrich offline
Posts: 10
Joined: Jan 02, 2012
Location: Oakville, Ontario

iTunes Pause and Speak

Hi guys,

Just wondering if the iTunes plugin is supposed to speak text through remote iTunes speakers? It's not working for me, and I have to assume that it should work this way otherwise I don't understand the point of the function (you could easily just use the Indigo native Speak feature that is available for each command).

I couldn't find an answer in the forums, so please forgive if the question has already been asked.

Cheers!
JE

JE

Posted on
Sat Jan 07, 2012 4:26 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: iTunes Pause and Speak

Nope - speaking goes through the computer's speakers. What makes it useful is using Airfoil to direct sound to remote speakers - so you can change the source in Airfoil to the Indigo server then speak, or do like I do and just direct all sound from the computer to the speakers.

And, as for using the standard speak - yes, you could, but then iTunes would continue to play while the speech is going on. I find that quite distracting.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jan 08, 2012 8:40 am
jehrich offline
Posts: 10
Joined: Jan 02, 2012
Location: Oakville, Ontario

Re: iTunes Pause and Speak

Thanks for the clarification. I would prefer to stick with just iTunes (higher WAF) so I'm trying to write a script that can do this. I'll share the results here if I'm successful. Can anyone point me in the right direction for passing parameters to AppleScripts or Python scripts?

Cheers!
JE

JE

Posted on
Sun Jan 08, 2012 9:27 am
jehrich offline
Posts: 10
Joined: Jan 02, 2012
Location: Oakville, Ontario

Re: iTunes Pause and Speak

Okay, here is my first attempt. There is a significant delay before and after the spoken text and if anyone has any ideas on how to reduce this I would love to hear them. To use the script, save it to Indigo's Attachments folder and call it from an Execute Script action as follows:

Code: Select all
speakItunesMessage("Hello World!")


Code: Select all
-- Plays a messageText over iTunes speakers.
-- by Jens Ehrich (jens@ehrich.ca), 2012-01-10
--
-- Based on "Speak iTunes Information by J. Yergey 2-Jun-2008
--
-- Creates file (or overwrires existing file) iTunesIndigoTempFile.aiff in system temporary directory.

on speakItunesMessage(messageText)
   
   -- Set up file and folder names.
   tell application "Finder"
      set tempFolder to path to temporary items -- System temporary items folder; deleted at each restart.
      set tempFile to tempFolder & "iTunesIndigoTempFile.aiff" as text -- Temporary file alias.
   end tell
   
   tell application "iTunes"
      
      -- Create an audio file of the messageText.
      -- Note that if the file already exists, it will be overwritten.
      say messageText saving to tempFile
      
      if player state is playing then
         -- Pause current playing iTunes track and save the position within the current track.
         set savedPosition to player position -- Save position within currently playing track.
         set savedTrack to current track -- Save current track and playlist info.
         set wasPlaying to true
      else
         set wasPlaying to false
      end if
      
      -- Add and play file with messageText, then delete the temporary track.
      set messageTextTrack to (add tempFile)
      play messageTextTrack with once
      repeat until (player state is not playing) -- Used to wait until track is finished.
      end repeat
      
      -- Resume playing previous track from same position.
      -- set player position to savedPosition
      if wasPlaying then
         play savedTrack
         -- pause
         set player position to savedPosition
         play savedTrack
      end if
      
      delete messageTextTrack
      
   end tell
   
end speakItunesMessage

JE

Posted on
Sun Jan 08, 2012 11:11 am
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: iTunes Pause and Speak

I'd find this functionality useful. I tried it out and see the same delay. My guess is that the AppleScript finder commands just take time. There must be a more efficient way to do this.

As an aside, I tried to run a little loop and it killed all other plugin communications:

Code: Select all
repeat 5 times
  speakItunesMessage("Hello World.")
end repeat

Posted on
Sun Jan 08, 2012 11:37 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: iTunes Pause and Speak

If you ran it as an embedded script then it's not surprising. Embedded AppleScripts have to be run on the main thread of the Indigo Server process - so if they do things that take a lot of time it hangs up the server. The better option is to run them as external scripts. Note, however, that by making it an attachment to Indigo it's going to cause the same issue - the attachment will have to run on the main thread of the server and will likely hang the server up.

If you're going to take this approach I'd suggest not making it an attachment but instead making it a standalone script. Then, rather than passing the message to the handler, just update a variable with the message to speak then call the script. The only communication the script would need to do with Indigo then would be to get the variable value. Everything else would be outside the server so as to not hang it up.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jun 01, 2014 10:08 pm
HowmaNoid offline
User avatar
Posts: 67
Joined: Apr 14, 2012

Re: iTunes Pause and Speak

So if you have iTunes on the server configured to connect to a couple of remote speakers via AirPlay (where the music is played OK from those speakers) the "Pause and Speak" function in the plugin will still only send speech over the server's direct connected audio hardware.

Have I got that right? If so, any thoughts on how you could support AirPlay directly? I'm having all kinds of terrible reliability problems with AirFoil. It drops speaker connections constantly whereas iTunes has no problem sending sound to those remote speakers 24x7.

Thanks

H

Posted on
Fri Jun 06, 2014 5:30 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: iTunes Pause and Speak

That's correct. The Indigo Server is the application generating the speech, not iTunes, so the output is going to the system output, not what's configured in iTunes. I'm surprised about your Airfoil reliability - I've run it for 6 years and rarely ever have connections drop. For a while (a couple of years ago) I did notice that it had some issues, so I wrote a simple little AppleScript that restarted it at 2am. I don't believe I'm running that any more though.

Unfortunately, even if there were an API for sending sound via Airplay (I'm not sure there is on the Mac - in the past Rogue Amoeba, makers of Airfoil, had to reverse engineer the protocol), you'd still have issues because only one thing can be streaming to an airplay device at a time - so since you're using iTunes to stream to them, another app wouldn't be able to.

I believe someone at one point had some hack that created a speech file, imported it into iTunes, then played it - thereby doing sorta what you're looking for. I never personally tried it so I can't say how well/reliably it worked and I don't find it with a cursory search so you may need to do more digging.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests