AppleScript: Save Text as Audio

Discussion in 'Mac Programming' started by Caleb531, Nov 23, 2009.

  1. Caleb531 macrumors 6502

    Caleb531

    Joined:
    Oct 17, 2009
    #1
    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)
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Try this:
    Code:
    say "hello" saving to POSIX file "/Users/you/Desktop/test.aif"
     
  3. Caleb531 thread starter macrumors 6502

    Caleb531

    Joined:
    Oct 17, 2009
    #3
    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
     
  4. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #4
    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."
     
  5. Caleb531 thread starter macrumors 6502

    Caleb531

    Joined:
    Oct 17, 2009
    #5
    Awesome. The parentheses are so helpful sometimes.

    Now I have a wonderful script. Thanks for all the help.
     

Share This Page