Convert a Text File to an AIF?

Hey,

This should be easy but so far nothing I’m trying is working.

Mostly variations of something like this:

set theFile to “:Users:TV:Music:iTunes:Indigo:Indigo Audio:Text.rtf” as alias

open for access theFile
set theText to theFile
say theText saving to “:Users:TV:Music:iTunes:Indigo:Indigo Audio:Text.aif”
close access theFile

Any help greatly appreciated!

Thanks,

Carl

Hi,

the main problem is, you have to convert the formatted text to plain text
because you won’t expect the result of speaking RTF text.
There is a convenient shell command textutil to do the conversion


set indigoAudioFolder to (path to music folder as text) & "iTunes:Indigo:Indigo Audio:"
set plainText to do shell script "textutil -convert txt -stdout " & quoted form of (POSIX path of indigoAudioFolder & "Text.rtf")
say plainText saving to file (indigoAudioFolder & "Text.aiff")


As always, works perfect…many thanks!!

Now my home automation system can read me the news.

Carl

Seems I need to change the source file to an RSS folder in Documents.

This compiles but doesn’t do the conversion.

set indigoAudioFolder to (path to music folder as text) & “iTunes:Indigo:Indigo Audio:”
set sourceFolder to (path to documents folder as text) & “RSS”

set plainText to do shell script "textutil -convert txt -stdout " & quoted form of (POSIX path of sourceFolder & “Text.rtf”)
say plainText saving to file (indigoAudioFolder & “Text.aif”)

Did I miss something?

Many thanks,

Carl

Edit: Oops… forgot the : after “RSS”. All better. Thanks again for the help.

RSS is XML, not RTF, the conversion expects RTF text

Thanks, guess I’ll need to convert it. Can the script be altered for that?

Thanks,

Carl

Adam’s instructions on how to post code to this site.

http://macscripter.net/viewtopic.php?pid=152306#p152306

AFAIK textutil cannot convert XML, but you probably don’t need the value of any tag.
System Events can parse XML files

Hey,

Turns out that the file I need to convert to an aif is a standard txt file, not an rtf.

Can this be modified to work using a txt file, not using the conversion?

set indigoAudioFolder to (path to music folder as text) & "iTunes:Indigo:Indigo Audio:"
        set plainText to do shell script "textutil -convert txt -stdout " & quoted form of (POSIX path of indigoAudioFolder & "Text.rtf")
        say plainText saving to file (indigoAudioFolder & "Text.aif")

Thanks,

Carl

plain text doesn’t need to be converted


set indigoAudioFolder to (path to music folder as text) & "iTunes:Indigo:Indigo Audio:"
set plainText to read file (indigoAudioFolder & "Text.txt")
say plainText saving to file (indigoAudioFolder & "Text.aif")

Bingo, thanks a bunch!

Slowly but surely I think I may get a handle on this stuff.

Carl