How to export text to AIFF, but with delays?

I’m trying to export a simple countdown to an AIFF file using AppleScript that sets a quarter second delay between each number, but I get a -1708 error when it attempts to save.

tell application "System Events"
	try
		say "10" using "Serena"
		delay 0.25
		say "9" using "Serena"
		delay 0.25
		say "8" using "Serena"
		delay 0.25
		say "7" using "Serena"
		delay 0.25
		say "6" using "Serena"
		delay 0.25
		say "5" using "Serena"
		delay 0.25
		say "4" using "Serena"
		delay 0.25
		say "3" using "Serena"
		delay 0.25
		say "2" using "Serena"
		delay 0.25
		say "1" using "Serena"
		delay 0.25
		say "Begin playback." using "Serena"
		saving to file (((path to desktop) as string) & "audio.aiff")
	on error
		display dialog "Didn't Work"
	end try
end tell

When using say in Terminal to output an AIFF easily, the reading rate is much too fast. Also, slowing it down with -r makes it sound like a record player that’s lost power. I’m sure it’s something embarrassingly simple but I can’t figure it out. Any help is appreciated.

Hi,

this cannot work.
saving to is a parameter of the say command and can be used only for a single line after say.
I recommend to save the files separately and join them in Garageband

Hi,

There was a way to adjust the way voices speak. You type certain symbols within the text to speak. There was one for pausing the voice. It think its in one of the developer documents at Apple. Something about text to speech. Searching …

gl,

Model: MacBook Pro
AppleScript: 2.2.3
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

I think this is the documentation:

https://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/SpeechSynthesisProgrammingGuide/FineTuning/FineTuning.html#//apple_ref/doc/uid/TP40004365-CH5-SW11

I have to reread this. It shows how to embed commands within the text to speak.

Editted: I’m not sure if these still work. The document was written in 2006 I think. Anyway, try the slnc embedded command.

Editted: Here’s the example from the documentation.


say "Don't forget to bring your hat, [[slnc 400]] sunglasses, [[slnc 400]] sandals, [[slnc 400]] and towel."

gl,

Hello. I made a shell script for saying stuff from text files in the terminal also, that didn’t work as well as it should, the voice becomes slightly distorted.

I suspect the reason for that to be that I fed it UTF8 text, and not UTF-16. If I’ll work more on that, then I’ll try to save the stream to a text file, and open it as unicode text in Apple Script, and take it from their.

This may not sound purely logical, but the do shell script operates on UTF-8, a normal Applescript string I believe is UTF-16, so at least the bytes are ordered differently, and when dealing with normal characters, there will usually be twice as many (2) bytes for a unicode string.
This may partly explain the increased speed in volume.

It doesn’t. How AppleScript stores a string is an implementation detail, and is irrelevant.

It may be that whatever you’re using at the CLI is trying to use the old Carbon speech synthesis.

They still work and this was exactly what I needed. Thank you very much! Here’s the (embarrassingly simple) final script:

say "10, [[slnc 500]] 9, [[slnc 500]] 8, [[slnc 500]] 7, [[slnc 500]] 6, [[slnc 500]] 5, [[slnc 500]] 4, [[slnc 500]] 3, [[slnc 500]] 2, [[slnc 500]] 1, [[slnc 500]] Begin playback." saving to file (((path to desktop) as string) & "audio.aiff")

Again, thank you kel1 and thanks to StefanK and McUsrII for their replies as well. :slight_smile:

Hello. I wasn’t really aware that the speech synthesizes was in the old carbon frameworks. I guess that is what I am using when I am using the Applescript say command But still, I have no other way of explaining the better quality when speaking text directly from Applescript, than speaking the same text from an osa script that gets it’s input from utf-8. That is, I still purport that the quality gets lowered if it comes from utf8 and has been transformed into unicode text, than it is if the text is spoken directly from an AppleScript string: Try for yourself:

This is what I used

I can see your logic, but I think it’s wrong. UTF8 is just a way of encoding text; it’s the content that matters. What gets passed to the speech synthesis API (which is a Cocoa API for the say command) is an NSString, which is an opaque class cluster.

I can’t explain why you’re seeing (hearing?) a difference, but I just can’t see how an input encoding issue can make any difference. Apart from anything else, osascript has to first compile the script before running it, so your variable will be converted to an AS string anyway.

Hello.

I’ll address this issuue, by actually encoding the text back to or encoding the text to UTF-16, when I have better time, as I am curious as it to how it sounds then, aware of that it may be other issues I am not aware of now, that I may be aware of then. :slight_smile: