Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applesctipt: Saving to multiple commands to one file...

Hello, I'm fairly new to AppleScript and have been playing around with text files using several say commands for fun. I don't want random voices. I want them set to particular passages of text within one file.


I've been looking everywhere to find out how to save the file to audio and haven't found anything useful other than the 'Saving to' command, but that only works for one line of code, unless I'm doing something wrong.


I guess what I need to know is:


1) Is there a way to compound the script while keeping the code intact? Not sure if that makes sense.

2) Is there a way to write another AppleScript file to Audio? I'm thinking that would work and have found many ideas on how to open files that aren't AppleScript, but I can't seem to figure out how to work with another script within a script. I would assume it would be a simple line of code, but I can't figure out where to start.


For a basic example of a Script I'd like to convert:


Script example

say "Hello, my name is Alex." using "Alex" volume 0.5 speaking rate 240 pitch 70

say "What's wrong with your voice?" using "Lee" volume 0.5 speaking rate 90


I haven't played with code for over 5 years and have gotten rusty. I'm fairly sure I can call a script within a script and execute it in a variety of ways. I just don't know how to do it in AppleScript. Would variables be the way to go? if so, how would I set the Voice to use pitch, rate, volume within the variable so that I could assign it to lines of text within the script? Sorry if this is complicated. I know it can be done. I have a feeling it might be simple. I had intermediate knowledge of a few different languages coming from the Windows platform in my past life.

MacBook Air (11-INCH, MID 2011), OS X Mountain Lion

Posted on Mar 16, 2014 7:44 PM

Reply
2 replies

Mar 16, 2014 9:10 PM in response to kreme

Part of your problem isn't rusty programming skills - more that you're trying to do something that just isn't supported 🙂


The 'say' command does have the ability to save the audio output to a file, but it's not designed to combine multiple distinct audio streams into one file - each invocation of 'say' is distinct.


On that basis, your best solution might be to separate your goals - one part that generates the various audio files with various voice settings, then a separate part that combines the individual audio snippets into one unified audio file. A divide and conquer approach.


On that basis, you could use variables to hold the pitch, volume, etc. values, but it doesn't offer a lot of advantages.

Mar 17, 2014 9:34 AM in response to kreme

What Camelot said.


Here's another approach to your Alex invocation:


set alexVoice to "Alex"

set AlexInflect to "[[Rate 240]][[volume 0.5]][[pitch 70]]"

set alexAudio to (the POSIX path of (path to desktop)) & "Alex.aiff"


set voiceIn to AlexInflect & "Hello, my name is Alex. "

--set voiceIn to "[[Rate 240]][[volume 0.5]][[pitch 70]]Here,, is my AppleScript."


-- write it silently then speak it

sayvoiceInusingalexVoicesaving toalexAudio with waiting until completion

sayvoiceInusingalexVoice


On the otherhand, if you were to incorporate the OS X say command in a do shell script invocation, you could use an AppleScript choose file prompt to get an input file to read from and pass that as a command-line variable argument to the OS X say command. See man say in the OS X Terminal.

Applesctipt: Saving to multiple commands to one file...

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.