Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Caleb531

macrumors 6502
Original poster
Oct 17, 2009
289
0
I have created a simple script that will display a dialog with a text box, and will speak whatever text is returned. I want to make the script a little more complicated by adding a feature to save the entered text (before spoken) as an audio file. What code can I use to accomplish this? (preferably AAC or AIFF)
 
Try this:
Code:
say "hello" saving to POSIX file "/Users/you/Desktop/test.aif"
 
Thank you so much! It worked flawlessly.

EDIT: I am currently using this code to choose a name for the file to be saved. Although, instead of saving the file, all it does it say the input words. Any help?
Code:
repeat
	set speakDialog to display dialog "Speak Text:" buttons {"Save", "Cancel", "Speak"} default button 3 default answer ""
	set choice to button returned of speakDialog
	set spoken to text returned of speakDialog
	if choice is equal to "Speak" then
		say spoken
	end if
	if choice is equal to "Save" then
		set nameDialog to display dialog "Name File (with extension)" buttons {"Cancel", "Save"} default button 2 default answer "text.aiff"
		set nameChoice to button returned of nameDialog
		set chosenName to text returned of nameDialog
		set spoken to text returned of speakDialog
		if nameChoice is equal to "Save" then
			say spoken saving to POSIX file "/Users/Squiddy22/Desktop/" & chosenName & ""
		end if
	end if
end repeat
 
Thank you so much! It worked flawlessly.

EDIT: I am currently using this code to choose a name for the file to be saved. Although, instead of saving the file, all it does it say the input words. Any help?
Code:
repeat
	set speakDialog to display dialog "Speak Text:" buttons {"Save", "Cancel", "Speak"} default button 3 default answer ""
	set choice to button returned of speakDialog
	set spoken to text returned of speakDialog
	if choice is equal to "Speak" then
		say spoken
	end if
	if choice is equal to "Save" then
		set nameDialog to display dialog "Name File (with extension)" buttons {"Cancel", "Save"} default button 2 default answer "text.aiff"
		set nameChoice to button returned of nameDialog
		set chosenName to text returned of nameDialog
		set spoken to text returned of speakDialog [B]-- this line probably unnecessary[/B]
		if nameChoice is equal to "Save" then
			say spoken saving to POSIX file "/Users/Squiddy22/Desktop/" & chosenName & ""
		end if
	end if
end repeat

This line isn't working:

POSIX file "/Users/Squiddy22/Desktop/" & chosenName & ""

Instead, you can do this:

POSIX file ("/Users/Squiddy22/Desktop/" & chosenName)

Not sure why this doesn't work as you wrote it but the parentheses help.

mt

P.S. Debugging tip: I caught the mistake by clicking on the "Events" button on the bottom half of the AppleScript Editor window, which is normally set to "Results."
 
Awesome. The parentheses are so helpful sometimes.

Now I have a wonderful script. Thanks for all the help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.