Wednesday, April 16, 2014

#1 2011-06-21 04:02:30 pm

wontonunist
Member
Registered: 2011-06-21
Posts: 24

Text-To-Speech App

I made a little app that takes text and uses Macintalk to speak it, but with added features like saving the speech to an audio file and selecting a voice you want to use from within the app. I wrote it a while ago, so the code is pretty scatterbrained, but if you can sift through it, you may find it helpful.

I have no doubt that there are much better ways to program this so it's more efficient and easy to read. If notice anything stupid about the syntax that I could be doing differently, please let me know. I'm always trying to improve!

I call it Speecher. Because that name is about as much of a real English word as the language that Mac speaks is the actual English language.

Applescript:

set list_of_voices to {"Alex", "Bruce", "Fred", "Junior", "Ralph", "Agnes", "Cathy", "Princess", "Vicki", "Victoria", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bubbles", "Cellos", "Deranged", "Good News", "Hysterical", "Pipe Organ", "Trinoids", "Whisper", "Zarvox"}
set audioFormats to {".au ", ".flac ", ".flv ", ".ogg ", ".wav ", ".wmv"}
set voice to "the default system voice."
set text_to_speak to ""
repeat
   set voice to (choose from list list_of_voices with prompt "Select your voice or click Continue to use " & voice with title "Choose Your Voice" OK button name "Continue" cancel button name "Quit" with empty selection allowed)
   if the result is false then return
   repeat
       set voice to voice as text
       if voice is "" then set voice to "the default system voice."
       set speechPrompt to (display dialog "Click Back to get a different voice, or to quit.

If nothing happens when you press the Speak button, try using a different voice.

Using "
& voice & "

Enter some text to speak:"
default answer text_to_speak buttons {"Back", "Save Audio", "Speak!"} default button 3 with title "Speecher")
       if button returned of speechPrompt is "Back" then
           exit repeat
       else if button returned of speechPrompt is "Speak!" then
           set text_to_speak to the text returned of speechPrompt
           if voice is "the default system voice." then
               say text_to_speak
           else
               try
                   say "" & text_to_speak & "" using "" & voice & ""
               on error
                   exit repeat
               end try
           end if
       else
           set text_to_speak to the text returned of speechPrompt
           if text_to_speak is "" then
               display dialog "Enter some text!" buttons {"Back"} default button 1 giving up after 3
               exit repeat
           end if
           set savePath to (choose file name with prompt ".AIFF FORMAT NEEDED FOR ITUNES PLAYBACK.
Quicktime not supported.

Other extensions include:
"
& audioFormats & "" default name ".aiff" default location (path to documents folder))
           try
               say text_to_speak using voice saving to savePath
           on error
               if voice is "the default system voice." then
                   say text_to_speak saving to savePath
               else
                   exit repeat
               end if
           end try
           set text_to_speak to ""
           set nextAction to the button returned of (display dialog "File saved!" buttons {"Quit", "Back to Speecher", "Show in Finder"} default button 2 with icon note)
           if nextAction is "Quit" then
               return
           else if nextAction is "Back to Speech" then
               exit repeat
           else
               tell application "Finder"
                   activate application "Finder"
                   reveal savePath
               end tell
               repeat
                   tell application "System Events"
                       set front_app to (item 1 of (get name of processes whose frontmost is true))
                       if front_app is "Speecher" then exit repeat
                       delay 0.1
                   end tell
               end repeat
               activate me
           end if
       end if
   end repeat
end repeat

Last edited by wontonunist (2011-06-21 04:07:47 pm)

Offline

 

#2 2011-06-24 04:40:25 pm

lemuralex13
Member
Registered: 2011-06-21
Posts: 77

Re: Text-To-Speech App

Maybe make it go back to the previous screen when you hit cancel in the save menu? You could use a "try" and have an "on error" statement to bring you back to the speaking menu if they close it or hit cancel

Im still looking through it, but the idea is definitely pretty cool! Also, it's, like you said, a little crazy & scattered, try adding some handlers and call them from the top (make sure to transfer your variables though).


Awesome ----> Alex | xelA <---- emosewA

Offline

 

#3 2011-07-09 08:42:59 pm

AudialRedux
Member
Registered: 2010-12-07
Posts: 45

Re: Text-To-Speech App

Hey Bro I've Added To Your Code Its Pretty Neat I'm Still Working On It So It Can Use Mp3 And Have A Choice To Which Format To Choose From smile I Hope You Don't Mind???

i added:
*welcome dialog
*if no text is used the program tells the user to input text
*Updated From "Speecher" to "Speecher v1.1"

Applescript:

set welcome to display dialog "Welcome To Speecher v1.1" & return & return & "How To Use:" & return & return & "Choose Your Voice, Then Enter The Text Of Your Choice You Type It Speecher Will Say It!, You Can Also Save The Voice File! Its That Easy" & return & return & "Copyright wontonunist (c) 2011" buttons {"Continue"} default button 1
if button returned of welcome is "Continue" then
   set list_of_voices to {"Alex", "Bruce", "Fred", "Junior", "Ralph", "Agnes", "Cathy", "Princess", "Vicki", "Victoria", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bubbles", "Cellos", "Deranged", "Good News", "Hysterical", "Pipe Organ", "Trinoids", "Whisper", "Zarvox"}
   set audioFormats to {".au ", ".flac ", ".flv ", ".ogg ", ".wav ", ".wmv"}
   set voice to "the default system voice."
   set text_to_speak to ""
end if
repeat
   set voice to (choose from list list_of_voices with prompt "Select your voice or click Continue to use " & voice with title "Choose Your Voice" OK button name "Continue" cancel button name "Quit" with empty selection allowed)
   if the result is false then return
   repeat
       set voice to voice as text
       if voice is "" then set voice to "the default system voice."
       set speechPrompt to (display dialog "Click Back to get a different voice, or to quit.

If nothing happens when you press the Speak button, try using a different voice.

Using "
& voice & "

Enter some text to speak:"
default answer text_to_speak buttons {"Back", "Save Audio", "Speak!"} default button 3 with title "Speecher v1.1")
       if button returned of speechPrompt is "Back" then
           exit repeat
       else if button returned of speechPrompt is "Speak!" then
           set text_to_speak to the text returned of speechPrompt
           if text returned of speechPrompt is "" then
               display dialog "Error: You Entered No Text For Speecher To Say!." buttons {"Back"} default button 1 with title "Error"
           end if
           if voice is "the default system voice." then
               say text_to_speak
           else
               try
                   say "" & text_to_speak & "" using "" & voice & ""
               on error
                   exit repeat
               end try
           end if
       else
           set text_to_speak to the text returned of speechPrompt
           if text_to_speak is "" then
               display dialog "Error: You Entered No Text For Speecher To Say!." buttons {"Back"} default button 1
               exit repeat
           end if
           set savePath to (choose file name with prompt ".AIFF FORMAT NEEDED FOR ITUNES PLAYBACK.
Quicktime not supported.

Other extensions include:
"
& audioFormats & "" default name ".aiff" default location (path to documents folder))
           try
               say text_to_speak using voice saving to savePath
           on error
               if voice is "the default system voice." then
                   say text_to_speak saving to savePath
               else
                   exit repeat
               end if
           end try
           set text_to_speak to ""
           set nextAction to the button returned of (display dialog "File saved!" buttons {"Quit", "Back to Speecher", "Show in Finder"} default button 2 with icon note)
           if nextAction is "Quit" then
               return
           else if nextAction is "Back to Speech" then
               exit repeat
           else
               tell application "Finder"
                   activate application "Finder"
                   reveal savePath
               end tell
               repeat
                   tell application "System Events"
                       set front_app to (item 1 of (get name of processes whose frontmost is true))
                       if front_app is "Speecher" then exit repeat
                       delay 0.1
                   end tell
               end repeat
               activate me
           end if
       end if
       
   end repeat
end repeat

Last edited by AudialRedux (2011-07-09 08:45:30 pm)

Offline

 

#4 2011-08-18 11:04:21 pm

wontonunist
Member
Registered: 2011-06-21
Posts: 24

Re: Text-To-Speech App

No, I don't mind at all! Well done, that's really cool.

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.056 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)