TTS (Text to speech)で遊ぶ。

入力したテキストを音声で読み上げ、もしくはaiffファイルに保存するAppleScript。

property dText : ""
on idle
display dialog "Please enter something." default answer dText buttons {"QUIT", "SAVE", "TEST"} default button 3
set dResult to result
button returned of dResult
set spText to text returned of dResult
if button returned of dResult is "QUIT" then
quit
else
if spText is not "" then
set dText to spText
-- [[rate 180]]で読み上げスピードを設定する
set theText to "[[rate 180]]" & spText
if button returned of dResult is "TEST" then
-- Victoria の声で読み上げ
say theText using "Victoria"
else
set saveFile to ((path to desktop as string) & spText & ".aiff")
say theText using "Victoria"
say theText using "Victoria" saving to file saveFile
end if
end if
end if
return 1
end idle



上記のスクリプトをスクリプトエディタから保存して実行します。
(「初期画面を表示しない」「実行後も終了しない」にチェックをつける)
一応OS 10.3.9 では動作確認済み。

Victoria 以外の声のリスト
http://docs.info.apple.com/article.html?path=AppleScript/2.1/jp/as304.html

| | コメント (0) | トラックバック (0)

AppleScriptでデスクトップにフォルダを新規作成する


set mDir to POSIX path of (path to desktop)
set fldName to "作成するフォルダ名"

-- もしfolder fldName がデスクトップ上に存在しなければ作成する
-- desktop / 新フォルダ ←こんな感じ

set fEx to do shell script "find " & mDir & " -name " & fldName & "* -print"
if fEx is "" then
do shell script "cd " & mDir & ";mkdir " & fldName
end if

-- ・さらに下の階層も作る場合

-- (下の階層に作るフォルダの名前を、その日の日付にしてみる)
-- desktop / 新フォルダ / 日付のフォルダ ←こんなイメージ

set theTime to do shell script "date +'%y%m%d'"
set fEx to do shell script "find " & mDir & fldName & "/" & " -name " & theTime & "* -print"
if fEx is "" then
do shell script "cd " & mDir & fldName & ";mkdir " & theTime
end if

| | コメント (0) | トラックバック (0)

Applescriptでhtmlタグを削除する

動作をApplescriptでやってみると…


-- < と > に挟まれた部分を削除する

set theText to 〜〜 -- 処理するテキスト

set oldDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to " <"
set m to count text items of theText
set AppleScript's text item delimiters to ">"
set t to count text items of theText
set AppleScript's text item delimiters to ","
if m > t then
set p to t
set min1 to m - t
else if m = t then
set p to m
set min1 to 0
else
set p to m
set min1 to t - m
end if
set p to p - 1
repeat until p < 1
set k to offset of " <" in theText
set s to offset of ">" in theText
set tid to strings k thru s of theText
set AppleScript's text item delimiters to tid
set theText to text items of theText
set AppleScript's text item delimiters to " "
set theText to theText as string
set AppleScript's text item delimiters to " <"
set h to count text items of theText
set AppleScript's text item delimiters to ">"
set r to count text items of theText
set AppleScript's text item delimiters to oldDel
if h > r then
set p to r
set min2 to h - r
else if h = r then
set p to h
set min2 to 0
else
set p to h
set min2 to r - h
end if
set p to p - 1
end repeat
end if

特に文字列操作に関しては Applescript だと要工夫。

| | コメント (0) | トラックバック (0)