Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

カテゴリー: Sound

Voice Character IDと音程、速度、音量を指定してテキスト読み上げ

Posted on 8月 28 by Takaaki Naganoya

AVSpeechSynthesizerを呼び出して、指定文字列を読み上げる(Text to Speech)AppleScriptです。

AppleScript標準装備のsayコマンドと比べて、声の高さや読み上げ速度の設定範囲が広いようで、未知の読み上げ音声が聞こえます。

Siriの音声キャラクタはまだ指定できないようですが、次のOSぐらいでできたりするものでしょうか? 

音声レンダリングした内容をファイルに書き込む方法が分かれば、さらにいろいろできそうです。

AppleScript名:Voice Character IDと音程、速度、音量を指定して読み上げ.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/08/28
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AVFoundation"
use scripting additions

set aSynth to current application’s AVSpeechSynthesizer’s alloc()’s init()
set aUtte to current application’s AVSpeechUtterance’s alloc()’s initWithString:"こんにちは。私の名前はおとやです。"
aUtte’s setVoice:(current application’s AVSpeechSynthesisVoice’s voiceWithIdentifier:"com.apple.voice.enhanced.ja-JP.Otoya")
–aUtte’s setVoice:(current application’s AVSpeechSynthesisVoice’s voiceWithIdentifier:"com.apple.voice.compact.ja-JP.Otoya")

(aUtte’s setRate:(0.6 as real)) –0.0から1.0。デフォルト 0.5 【速度】
(
aUtte’s setPitchMultiplier:(1.8 as real)) –0.5から2.0。デフォルト1.0 【音程】
(
aUtte’s setVolume:(1.0 as real)) –0.0から1.0。デフォルト1.0 【音量】

(aSynth’s speakUtterance:(aUtte))

★Click Here to Open This Script 

Posted in Sound Text | Tagged 12.0savvy 13.0savvy AVSpeechSynthesisVoice AVSpeechSynthesizer AVSpeechUtterance | Leave a comment

SHARP MZ MML再生_アルハンブラ_mono

Posted on 1月 11 by Takaaki Naganoya

はるかかなた昔の、MZ-80Bが採用していた単音3オクターブの範囲の音楽再生を行うPLAY文、それに準拠したポケットコンピュータ用の音楽再生プログラムのデータ「アルハンブラの想い出」の再生を行うため「だけ」に、そのMML再生プログラムをAppleScriptで作ってみたものです(2時間ぐらいだったか)。

音階再生用に、オープンソースの「MPSoundEngine」フレームワークをUniversal Binaryでビルドし直して、これを用いて音階データと音の長さのデータのテーブルを作って再生しています。

–> Download mpSoundKit_univ.framework(To ~/Library/Frameworks)

オリジナルのMZにしてもポケットコンピュータのMML再生プログラムにしても、単音しか出ない仕様ですが、このデータの原作者が楽譜を細切れにしてアルペジオ奏法で演奏させているかのような効果を生み出しています。これは、当時も腰を抜かしましたが、普通こんなものはやらない狂気の産物、人類レベルの遺産といえます。

→ 本AppleScriptの再生ムービー

MPSoundEngineをフレームワーク化したものを呼び出しているため、実行にはScript Debuggerが必要です。macOS 11よりも古い環境では以前に掲載したFramework(Intelバイナリのみ)がそのまま利用できるはずです。

まだ、いまひとつ休符(R)の処理などがうまく行っていないようで、この曲以外のデータを再生させると、首をひねってしまう演奏をしてしまうものの、それはオリジナルのデータの出来がよくなかったのか、あるいはこのプログラムの再現度が高くないためかは不明です。

AppleScript名:SHARP MZ MML再生_アルハンブラ_mono.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/12/22
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine
use scripting additions

script spd
  property musStr : ""
  
property musList : {}
  
property mmlList : {}
end script

set octL to {"-C", "-#C", "-D", "-#D", "-E", "-F", "-#F", "-G", "-#G", "-A", "-#A", "-B", "C", "#C", "D", "#D", "E", "F", "#F", "G", "#G", "A", "#A", "B", "+C", "+#C", "+D", "+#D", "+E", "+F", "+#F", "+G", "+#G", "+A", "+#A", "+B"}

set lenL to {130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.0, 196.0, 207.65, 220.0, 233.08, 246.94, 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.0, 415.3, 440.0, 466.16, 493.88, 523.25, 554.37, 587.33, 622.25, 659.25, 698.46, 739.99, 783.99, 830.61, 880.0, 932.33, 987.77}

set noteList to {"9", "8", "7", "6", "5", "4", "3", "2", "1", "0"}
set noteTime to {4, 3, 2, 1.5, 1, 0.75, 0.5, 0.375, 0.25, 0.125}

set aDict to current application’s NSMutableDictionary’s dictionaryWithObjects:(lenL) forKeys:(octL)
set bDict to current application’s NSMutableDictionary’s dictionaryWithObjects:(noteTime) forKeys:(noteList)

set (musStr of spd) to "-A0+E+E+EE+E+E+E+C0+E+E+EE+E+E+EB0+D+D+DE+D+D+D-A0+C+C+CE+C+C+CA0+C+C+CE+C+C+CB0+D+D+DE+D+D+D-A0+E+E+EE+E+E+E+C0+E+E+EE+E+E+E+C0+E+E+EE+E+E+E-A0+E+E+EE+E+E+E+C0+E+E+EE+E+E+E+D0+F+F+FG+F+F+FC0+G+G+GG+G+G+G+E0+G+G+GG+G+G+G+E0+F+F+FG+F+F+FC0+E+E+EG+E+E+E+C0+E+E+EG+E+E+E+D0+F+F+FG+F+F+FC0+G+G+GG+G+G+G+E0+G+G+GG+G+G+G+E0+G+G+GG+G+G+GC0+G+G+GG+G+G+G+E0+G+G+GG+G+G+G+E0+G+G+GG+G+G+G-F0+C+C+CC+C+C+CA0+C+C+CC+C+C+CG0+B+B+BC+B+B+B-F0+A+A+AC+A+A+A+F0+A+A+AC+A+A+A-D0+B+B+BF+B+B+B-E0+A+A+AB+A+A+A+E0+#G+#G+#GB0+#G+#G+#G+E0+#G+#G+#GB0+#G+#G+#G-E0+#G+#G+#G+D0+#G+#G+#G+E0+#G+#G+#G+D0+#G+#G+#G+E0+#G+#G+#G+D0+#G+#G+#G-A0+#A+#A+#A+#C0+#A+#A+#A+E0+#A+#A+#A+#C0+#A+#A+#A+E0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BBBFBBBA0+C+C+CF+C+C+CA0+B+B+BF+B+B+B-A0+E+E+EE+E+E+E+#C0+E+E+EE+E+E+E+#C0+E+E+EE+E+E+E-A0+E+E+EE+E+E+E+#C0+E+E+EE+E+E+E+#C0+E+E+EE+E+E+E-E0+#G+#G+#GE0+#G+#G+#G+E0+#G+#G+#GE0+#G+#G+#G+E0+#G+#G+#GE0+#G+#G+#G-E0+#F+#F+#FE0+#F+#F+#F+#C0+E+E+EE+E+E+EB0+D+D+DE+D+D+D-A0+#C+#C+#CE0+#C+#C+#CA0+#C+#C+#CE0+#C+#C+#C#F0+#C+#C+#CA0+#C+#C+#C-A0+#C+#C+#CE0+#C+#C+#CA0+#C+#C+#C-E0+#C+#C+#C-#B0+#C+#C+#C#C0+#C+#C+#C-A0+#C+#C+#CE0+#C+#C+#CA0+#C+#C+#C-E0+#C+#C+#C-#B0+#C+#C+#C#C0+#C+#C+#C-A3EA+#C+E+A+E8A7R7"

set baseTime to 0.25
set (musList of spd) to characters of (musStr of spd)
set octV to 0 –Ave Octave

set defaultNote to {octave:0, noteStr:missing value, sharpF:missing value, flatF:missing value, noteLength:missing value}
copy defaultNote to curNote

set prevNoteLength to -1
set (mmlList of spd) to {}

repeat with i in (musList of spd)
  set j to contents of i
  
  
considering case
    if j = "-" then
      if noteStr of curNote is not equal to missing value then
        set the end of (mmlList of spd) to curNote
        
set prevNoteLength to noteLength of curNote
        
        
copy defaultNote to curNote
        
set (noteLength of curNote) to prevNoteLength
        
set octave of curNote to -1
      else
        set octave of curNote to -1
      end if
      
    else if j = "+" then
      if noteStr of curNote is not equal to missing value then
        set the end of (mmlList of spd) to curNote
        
set prevNoteLength to noteLength of curNote
        
        
copy defaultNote to curNote
        
set (noteLength of curNote) to prevNoteLength
        
set octave of curNote to 1
      else
        set octave of curNote to 1
      end if
      
      
(*
    else if j = "b" then –Flat
      if noteStr of curNote is not equal to missing value then
        set the end of mmlList to curNote
        set prevNoteLength to noteLength of curNote
        
        copy defaultNote to curNote
        set (noteLength of curNote) to prevNoteLength
      else
        set flatF of curNote to true
      end if
      *)

    else if j = "#" then –Sharp
      if noteStr of curNote is not equal to missing value then
        set the end of (mmlList of spd) to curNote
        
set prevNoteLength to noteLength of curNote
        
        
copy defaultNote to curNote
        
set (noteLength of curNote) to prevNoteLength
      else
        set sharpF of curNote to true
      end if
      
    else if j is in {"C", "D", "E", "F", "G", "A", "B", "R"} then
      if noteStr of curNote is not equal to missing value then
        set the end of (mmlList of spd) to curNote
        
set prevNoteLength to noteLength of curNote
        
        
copy defaultNote to curNote
        
set (noteLength of curNote) to prevNoteLength
        
      end if
      
      
set (noteStr of curNote) to j
      
    else if j is in noteList then
      set noteLength of curNote to j
      
if noteStr of curNote is not equal to missing value then
        set the end of (mmlList of spd) to curNote
        
set prevNoteLength to noteLength of curNote
        
        
copy defaultNote to curNote
        
set (noteLength of curNote) to prevNoteLength
      else
        set the end of (mmlList of spd) to curNote
      end if
      
    end if
  end considering
  
end repeat

if noteStr of curNote is not equal to missing value then set the end of (mmlList of spd) to curNote –Append Last Item
–return mmlList

–Play
set engine to current application’s MPMonoSoundEngine’s alloc()’s init()
engine’s start()

repeat with i in (mmlList of spd)
  set j to contents of i
  
  
set curOctave to octave of j
  
set curOctaveStr to encodeOctave(curOctave) of me
  
  
set sharpFlag to sharpF of j
  
set flatFlag to flatF of j
  
set sfStr to encodeSharpAndFlat(sharpFlag, flatFlag) of me
  
  
set noteLenStr to noteLength of j
  
set noteLenTime to (bDict’s valueForKey:noteLenStr) as real
  
  
set noteString to noteStr of j
  
if noteString = "R" then
    engine’s |stop|()
    (
current application’s NSThread’s sleepForTimeInterval:(((noteLenTime * baseTime)) as real))
    
–delay (noteLenTime * baseTime) / 2
    
engine’s start()
  else
    set noteKey to curOctaveStr & sfStr & noteString
    
try
      set noteFreq to (aDict’s valueForKey:noteKey) as real
    on error
      engine’s |stop|()
      
return
    end try
    
    (
engine’s channel’s setFrequency:noteFreq)
    
–(engine’s rightChannel()’s setFrequency:noteFreq)
    
    (
current application’s NSThread’s sleepForTimeInterval:(((noteLenTime * baseTime)) as real))
    
  end if
end repeat

engine’s |stop|()

on encodeSharpAndFlat(sharpF, flatF)
  if {sharpF, flatF} = {missing value, missing value} then return ""
  
if {sharpF, flatF} = {true, missing value} then return "#"
  
if {sharpF, flatF} = {missing value, true} then return "b"
  
if {sharpF, flatF} = {true, true} then error "Sharp and Flat in one note"
end encodeSharpAndFlat

on encodeOctave(curOctave)
  if curOctave = 0 then
    set curOctaveStr to ""
  else if curOctave = 1 then
    set curOctaveStr to "+"
  else if curOctave = -1 then
    set curOctaveStr to "-"
  end if
  
return curOctaveStr
end encodeOctave

★Click Here to Open This Script 

Posted in Sound | Leave a comment

AVFAudioでオーディオ再生のじっけん

Posted on 2月 23, 2021 by Takaaki Naganoya

macOS 11.3で追加されたAVFAudio.frameworkを用いてオーディオ再生を行うAppleScriptです。

実行にはmacOS 11.3以降が必要です。オーディオファイル以外(ムービーなど)を渡すと終了します。

AppleScript名:AVFAudio test 1
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/02/23
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—

use AppleScript version "2.7" — macOS 11.3 or later
use framework "Foundation"
use framework "AppKit"
use framework "AVFAudio"
use scripting additions

set posixPath to POSIX path of (choose file with prompt "Choose an Audio file:")
set theURL to current application’s |NSURL|’s fileURLWithPath:posixPath
set aPlayer to current application’s AVAudioPlayer’s alloc()’s initWithContentsOfURL:theURL |error|:(missing value)
if aPlayer = missing value then return

aPlayer’s play()
delay 30
aPlayer’s |stop|()

★Click Here to Open This Script 

Posted in Sound | Tagged 11.0savvy | Leave a comment

mapboxSpeech Sample

Posted on 9月 27, 2019 by Takaaki Naganoya

mapboxが提供しているMapBoxSpeechフレームワークを呼び出すAppleScriptです。

mapboxは地図系の各種機能をWeb APIで提供しています。その一環としてGithub上でNatural-sounding text-to-speech Frameworkを提供しており、これをAppleScriptから呼び出してみました。

Github上のサンプルコードでは、AppleScript(Xcode上のプロジェクト)から呼び出すサンプルも掲載されているのですが、通常のScript EditorやScript Debugger上から呼び出す方法は掲載されていませんでした(しかも、サンプルそのままだと動く気配がないんですが、、、)。

# Xcode上で作成したアプリケーションだと、MapboxSpeech.Frameworkが、組み込んだアプリケーション側のInfo.plist内の指定のエントリに書かれているAccess tokenを読み込んでREST APIにアクセスできるとか。単体でAppleScriptからFrameworkを呼び出すような使い方は想定していなかったようです>サンプル

そこで、実際にmapboxにサインアップして、API Key(というか、プロジェクト単位でのToken)を取得、実際にGithub上で公開されているフレームワークをmacOS用にビルドし、通常のAppleScriptから呼び出してみました。

以下のアプレットは実行すると実際に日本語サンプル(たぶん)の文章を読み上げてくれます。実際に本Script(アプレットではなく)をAppleScriptとしてご自分の環境で動かすためには、Frameworkをインストールし、Script Debugger上で動かす(macOS 10.14以降)か、SIPを解除した環境(macOS 10.14以降)でスクリプトエディタ上で実行することになります。その際には、mapboxのWebサイト上でサインアップしてご自分のAccess tokenを取得してください。サインアップすると公開Access tokenを取得できますが、そちらではなく個別のプロジェクトをWebサイト上で作成して(Test AppleScriptとか)、そちらのAccess tokenを利用してください。

–> Download MapboxSpeech.framework(To ~/Library/Frameworks/)

–> mapboxSpeech Sample Run-Only(Code-Signed Executable Applet with Framework)

……で、実際にサンプル文章を読み上げてみたところ、英文なのに英文っぽくない日本語みたいな発音で、ちょっと「ナニコレ?」と思ってしまいましたが、冗談半分で日本語テキストをパラメータに指定してみたら、ちゃんと日本語を読み上げるのでビビりました。

この手のWebサービスで日本語対応はしておらず、英語+ヨーロッパの数カ国語のみサポートというのが普通です。

OS標準のsayコマンドよりも形態素解析が弱いようなので、文節ごとに読点(、)を入れてあげる必要はありますが、それでも日本語のテキストを読み上げてしまうのにはちょっと驚かされました。

AppleScript名:mapboxSpeech Sample.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/09/27
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "MapboxSpeech" –https://github.com/mapbox/mapbox-speech-swift
use framework "AVFoundation"
use scripting additions

on run
  set theOptions to current application’s MBSpeechOptions’s alloc()
  
theOptions’s initWithText:"こんにちは、私の名前は、「ながのや」 です。"
  
  
set speechSynthesizer to current application’s MBSpeechSynthesizer’s alloc()’s initWithAccessToken:"xx.xxX.X_XXxxxxxXXXXXxXxXXxxX"
  
set theURL to speechSynthesizer’s URLForSynthesizingSpeechWithOptions:theOptions
  
set theData to the current application’s NSData’s dataWithContentsOfURL:theURL
  
  
set aAudioPlayer to current application’s AVAudioPlayer’s alloc()’s initWithData:theData |error|:(missing value)
  
aAudioPlayer’s prepareToPlay()
  
aAudioPlayer’s setNumberOfLoops:0
  
aAudioPlayer’s setDelegate:me
  
aAudioPlayer’s play()
end run

–音楽再生の終了のDelegate Methodを取得
on audioPlayerDidFinishPlaying:anAudioplayer successfully:aFlag
  tell current application to quit
end audioPlayerDidFinishPlaying:successfully:

★Click Here to Open This Script 

Posted in REST API Sound Text to Speech | Tagged 10.12savvy 10.13savvy 10.14savvy | Leave a comment

System UI Soundが有効になっているかどうかをチェック v2

Posted on 7月 6, 2018 by Takaaki Naganoya

「システム環境設定」の「サウンド」で、「ユーザーインタフェースのサウンドエフェクトを再生」がオンになっているかどうかを確認するAppleScriptです。


▲false(左)、true(右)

本Blogのアーカイブ本の作成のために過去の記事を整理していたら、本Scriptを発掘し、いまの環境では動かない記述内容だったので書き換えてみたものです。


▲アーカイブ本、1年分で300〜400ページぐらいになりそうで、、、

AppleScript名:System UI Soundが有効になっているかどうかをチェック v2
set sRes to getEnableUISound() of me
–> true / false

–System UI Soundが有効になっているかどうかをチェック
on getEnableUISound()
  set a to do shell script "defaults read ’Apple Global Domain’ ’com.apple.sound.uiaudio.enabled’"
  
return (a = "1")
end getEnableUISound

★Click Here to Open This Script 

Posted in boolean Sound System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

AVCapture Deviceの情報を取得する

Posted on 4月 7, 2018 by Takaaki Naganoya
AppleScript名:AVCapture Deviceの情報を取得する
— Created 2017-10-24 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AVFoundation"
–https://github.com/pombredanne/osx_headers/blob/master/Frameworks/AVFoundation/AVCaptureHALDevice.h

set inputDevs to current application’s AVCaptureDevice’s devices()

set a1Res to (inputDevs’s valueForKeyPath:"manufacturer") as list
–>  {​​​​​"ma++ ingalls for Cycling ’74", ​​​​​"Shape Services", ​​​​​"Apple Inc.", ​​​​​"Shape Services", ​​​​​"ma++ ingalls for Cycling ’74", ​​​​​"Allocinit.com", ​​​​​"Allocinit.com", ​​​​​"Apple Inc."​​​}

set a2Res to (inputDevs’s valueForKeyPath:"localizedName") as list
–>  {​​​​​"Soundflower (64ch)", ​​​​​"Mobiola Headphone", ​​​​​"内蔵マイク", ​​​​​"Mobiola Microphone", ​​​​​"Soundflower (2ch)", ​​​​​"CamTwist", ​​​​​"CamTwist (2VUY)", ​​​​​"FaceTime HDカメラ(内蔵)"​​​}

set a3Res to (inputDevs’s valueForKeyPath:"isConnected") as list
–>  {​​​​​1, ​​​​​1, ​​​​​1, ​​​​​1, ​​​​​1, ​​​​​1, ​​​​​1, ​​​​​1​​​}

set a4Res to (inputDevs’s valueForKeyPath:"activeFormat") as list
–>  {​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x610000605a30> ’soun’/’lpcm’ SR=44100,FF=30,BPP=256,FPP=1,BPF=256,CH=64,BPC=32, ​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x618000407a90> ’soun’/’lpcm’ SR=48000,FF=30,BPP=4,FPP=1,BPF=4,CH=1,BPC=32, ​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x608000c171f0> ’soun’/’lpcm’ SR=44100,FF=4,BPP=8,FPP=1,BPF=8,CH=2,BPC=24, ​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x600000c0ba40> ’soun’/’lpcm’ SR=48000,FF=30,BPP=4,FPP=1,BPF=4,CH=1,BPC=32, ​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x610000606310> ’soun’/’lpcm’ SR=44100,FF=30,BPP=8,FPP=1,BPF=8,CH=2,BPC=32, ​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x618000a07010> ’vide’/’BGRA’ enc dims = 720×480, pres dims = 720×480 { 30.00 fps }, ​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x608000a15070> ’vide’/’2vuy’ enc dims = 720×480, pres dims = 720×480 { 30.00 fps }, ​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x610000605bb0> ’vide’/’2vuy’ enc dims = 160×120, pres dims = 160×120 { 29.97 25.00 24.00 15.00 fps }​​​}

set a5Res to (inputDevs’s valueForKeyPath:"transportType") as list
–>  {​​​​​0, ​​​​​0, ​​​​​1.651274862E+9, ​​​​​0, ​​​​​0, ​​​​​1.651274862E+9, ​​​​​1.651274862E+9, ​​​​​1.651274862E+9​​​}

set a6Res to (inputDevs’s valueForKeyPath:"modelID") as list
–>  {​​​​​"com_cycling74_driver_SoundflowerDevice:Soundflower", ​​​​​"com_ShapeServices_driver_HSAudioDevice:Headset Audio Device", ​​​​​"AppleHDA:40", ​​​​​"com_ShapeServices_driver_HSAudioDevice:Headset Audio Device", ​​​​​"com_cycling74_driver_SoundflowerDevice:Soundflower", ​​​​​"Stiltskin", ​​​​​"Stiltskin", ​​​​​"UVC Camera VendorID_1452 ProductID_34064"​​​}

set a7Res to (inputDevs’s valueForKeyPath:"formats") as list
–>  {​​​​​{​​​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x610000606240> ’soun’/’lpcm’ SR=192000,FF=30,BPP=256,FPP=1,BPF=256,CH=64,BPC=32, ​​​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x610000605d30> ’soun’/’lpcm’ SR=176400,FF=30,BPP=256,FPP=1,BPF=256,CH=64,BPC=32, ​​​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x610000605020> ’soun’/’lpcm’ SR=96000,FF=30,BPP=256,FPP=1,BPF=256,CH=64,BPC=32, ​​​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x610000605a90> ’soun’/’lpcm’ SR=88200,FF=30,BPP=256,FPP=1,BPF=256,CH=64,BPC=32, ​​​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x610000601b70> ’soun’/’lpcm’ SR=48000,FF=30,BPP=256,FPP=1,BPF=256,CH=64,BPC=32, ​​​​​​​(AVCaptureDeviceFormat) <AVCaptureDeviceFormat: 0x610000605a30> ’soun’/’lpcm’ SR=44100,FF=30,BPP=256,FPP=1,BPF=256,CH=64,BPC=32​​​​​},

set a8Res to (inputDevs’s valueForKeyPath:"connectionID") as list
–>  {​​​​​65, ​​​​​40, ​​​​​200, ​​​​​47, ​​​​​54, ​​​​​33, ​​​​​36, ​​​​​39​​​}

set a9Res to (inputDevs’s valueForKeyPath:"connectionUnitComponentSubType")
–>  (NSArray) {​​​​​1751215136, ​​​​​1751215136, ​​​​​1751215136, ​​​​​1751215136, ​​​​​1751215136, ​​​​​1684106272, ​​​​​1684106272, ​​​​​1684106272​​​}

set a10Res to (inputDevs’s valueForKeyPath:"deviceID") as list
–>  {​​​​​65, ​​​​​40, ​​​​​200, ​​​​​47, ​​​​​54, ​​​​​33, ​​​​​36, ​​​​​39​​​}

set a11Res to (inputDevs’s valueForKeyPath:"deviceSystem") as list
–>  {​​​​​2, ​​​​​2, ​​​​​2, ​​​​​2, ​​​​​2, ​​​​​1, ​​​​​1, ​​​​​1​​​}

set a12Res to (inputDevs’s valueForKeyPath:"isInUseByAnotherApplication") as list
–>  {​​​​​0, ​​​​​0, ​​​​​0, ​​​​​0, ​​​​​0, ​​​​​0, ​​​​​0, ​​​​​0​​​}

set a13Res to (inputDevs’s valueForKeyPath:"activeInputSource") as list
–>  {​​​​​missing value, ​​​​​missing value, ​​​​​(AVCaptureDeviceInputSource) <AVCaptureDeviceInputSource: 0x610000606290 ’imic’ "内蔵マイク">, ​​​​​missing value, ​​​​​missing value, ​​​​​missing value, ​​​​​missing value, ​​​​​missing value​​​}

set a14Res to (inputDevs’s valueForKeyPath:"uniqueID") as list
–>  {​​​​​"SoundflowerEngine:1", ​​​​​"HSAudioPipeEngine:0", ​​​​​"AppleHDAEngineInput:1B,0,1,0:1", ​​​​​"HSAudioPipeEngine:1", ​​​​​"SoundflowerEngine:0", ​​​​​"CDC85FD0-E73A-4FC2-B3A8-EA237D6990E0", ​​​​​"CDC85FD0-E73A-4FC2-B3A8-EA237D6990E1", ​​​​​"0x1a11000005ac8510"​​​}

set a15Res to (inputDevs’s valueForKeyPath:"inputSources") as list
–>  {​​​​​{}, ​​​​​{}, ​​​​​{​​​​​​​(AVCaptureDeviceInputSource) <AVCaptureDeviceInputSource: 0x610000606290 ’imic’ "内蔵マイク">​​​​​}, ​​​​​{}, ​​​​​{}, ​​​​​{}, ​​​​​{}, ​​​​​{}​​​}

set a16Res to (inputDevs’s valueForKeyPath:"description") as list
–>  {​​​​​"<AVCaptureHALDevice: 0x6180002f6d80 [Soundflower (64ch)][SoundflowerEngine:1]>", ​​​​​"<AVCaptureHALDevice: 0x6000002fba00 [Mobiola Headphone][HSAudioPipeEngine:0]>", ​​​​​"<AVCaptureHALDevice: 0x6180002fbe80 [内蔵マイク][AppleHDAEngineInput:1B,0,1,0:1]>", ​​​​​"<AVCaptureHALDevice: 0x6180002e8900 [Mobiola Microphone][HSAudioPipeEngine:1]>", ​​​​​"<AVCaptureHALDevice: 0x6100004f2c00 [Soundflower (2ch)][SoundflowerEngine:0]>", ​​​​​"<AVCaptureDALDevice: 0x7f804e6bae00 [CamTwist][CDC85FD0-E73A-4FC2-B3A8-EA237D6990E0]>", ​​​​​"<AVCaptureDALDevice: 0x7f804e5a3fa0 [CamTwist (2VUY)][CDC85FD0-E73A-4FC2-B3A8-EA237D6990E1]>", ​​​​​"<AVCaptureDALDevice: 0x7f804e5a24c0 [FaceTime HDカメラ(内蔵)][0x1a11000005ac8510]>"​​​}

★Click Here to Open This Script 

Posted in Image Sound System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

soundIO Libで現在のサウンド入出力デバイス名を取得

Posted on 2月 17, 2018 by Takaaki Naganoya

現在設定されているサウンド入出力デバイス名を取得するAppleScriptです。

–> soundIO Lib

AppleScript名:soundIO Libで現在のサウンド入出力デバイス名を取得
use AppleScript version "2.4"
use scripting additions
use soundIO : script "soundIO Lib" version "1.2" without importing

set i2 to soundIO’s getCurrentAudioInuptDevice()
set o2 to soundIO’s getCurrentAudioOutuptDevice()

return {i2, o2}
–> {"Built-in Microphone", "Built-in Output"}

★Click Here to Open This Script 

Posted in Sound System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

soundIO Libでサウンド入出力を変更 v2.0

Posted on 2月 17, 2018 by Takaaki Naganoya

サウンドの入出力デバイスを任意のデバイスに変更するAppleScriptです。

–> soundIO Lib (To ~/Library/Script Libraries)

AppleScript名:soundIO Libでサウンド入出力を変更 v2.0
— Created 2016-10-07 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use soundIO : script "soundIO Lib" version "1.2" without importing

set outList to soundIO’s getEveryAudioOutputDevice()
set targOutputDevice to contents of first item of (choose from list outList with prompt "Select Sound Output Device")

set inList to soundIO’s getEveryAudioInputDevice()
set targIntputDevice to contents of first item of (choose from list inList with prompt "Select Sound Intput Device")

–入出力デバイスを設定
set i1 to soundIO’s setAudioInuptDevice(targIntputDevice)
set o1 to soundIO’s setAudioOutuptDevice(targOutputDevice)

set aRes to ({i1, o1} = {true, true})
return aRes

★Click Here to Open This Script 

Posted in Sound System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

soundIO Libでサウンド入出力を標準デバイスに設定

Posted on 2月 17, 2018 by Takaaki Naganoya

サウンドの入出力デバイスを標準デバイスに変更するAppleScriptです。

ただし、Mac miniではデフォルトのオーディオ入力デバイスが存在していないため、エラーになります。

–> soundIO Lib

AppleScript名:soundIO Libでサウンド入出力を標準デバイスに設定
use AppleScript version "2.4"
use scripting additions
use soundIO : script "soundIO Lib" version "1.2" without importing

set targOutputDevice to "Built-in Output"
set targIntputDevice to "Built-in Microphone" –Mac mini does not have default sound input device

–出力デバイス一覧に設定対象が入っているかチェック
set aList to soundIO’s getEveryAudioOutputDevice()
if targOutputDevice is not in aList then return {false, "Target output device seems to not present"}

–入力デバイス一覧に設定対象が入っているかチェック
set bList to soundIO’s getEveryAudioInputDevice()
if targIntputDevice is not in bList then return {false, "Target input device seems to not present"}

–入出力デバイスを設定
set i1 to soundIO’s setAudioInuptDevice(targIntputDevice)
set o1 to soundIO’s setAudioOutuptDevice(targOutputDevice)

–サウンド入出力デバイスの変更確認
set i2 to soundIO’s getCurrentAudioInuptDevice()
set o2 to soundIO’s getCurrentAudioOutuptDevice()

set aRes to ({i1, o1} = {true, true}) and ({i2, o2} = {targIntputDevice, targOutputDevice})

return aRes

★Click Here to Open This Script 

Posted in Sound System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

soundIO Libでサウンド入出力をSoundFlowerに設定

Posted on 2月 17, 2018 by Takaaki Naganoya

サウンドの入出力デバイスをSoundFolwerに変更するAppleScriptです。

SoundFlowerをインストールしていない環境ではエラーになります。

–> soundIO Lib

AppleScript名:soundIO Libでサウンド入出力をSoundFlowerに設定
use AppleScript version "2.4"
use scripting additions
use soundIO : script "soundIO Lib" version "1.2" without importing

set targDevice to "Soundflower (2ch)"

set aList to soundIO’s getEveryAudioOutputDevice()
if targDevice is not in aList then return false

set bList to soundIO’s getEveryAudioInputDevice()
if targDevice is not in bList then return false

set i1 to soundIO’s setAudioInuptDevice(targDevice)
set o1 to soundIO’s setAudioOutuptDevice(targDevice)

set i2 to soundIO’s getCurrentAudioInuptDevice()
set o2 to soundIO’s getCurrentAudioOutuptDevice()

set aRes to (i1 = true and o1 = true) and (i2 = targDevice and o2 = targDevice)
return aRes

★Click Here to Open This Script 

Posted in Sound System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

soundIO Libでサウンド入出力デバイス名一覧を取得

Posted on 2月 17, 2018 by Takaaki Naganoya

サウンドの入出力デバイス名の一覧を取得するAppleScriptです。

サウンドの入出力先を取得したり変更するのにシステム環境設定をGUI Scripting経由で操作している例をよく見かけますが、あまり上品なやり方ではないのでこのようなライブラリを利用することをお勧めします。

–> soundIO Lib

use soundIO : script “soundIO Lib” version “1.2” without importing

と、useコマンドでAppleScript Librariesを読み込む際に、オプションで「without importing」を指定しています。

これは、デフォルトの状態ではライブラリ本体の書き換えがすぐに反映されなかった(キャッシュされていた)ことに対処したものです。それほど頻繁にライブラリ側の書き換えを行わなければ、指定する必要はないでしょう。

AppleScript名:soundIO Libでサウンド入出力デバイス名一覧を取得
use AppleScript version "2.4"
use scripting additions
use soundIO : script "soundIO Lib" version "1.2" without importing

set outList to soundIO’s getEveryAudioOutputDevice()
–> {"Built-in Output", "Mobiola Headphone", "Mobiola Microphone", "Soundflower (2ch)", "Soundflower (64ch)"}

set inList to soundIO’s getEveryAudioInputDevice()
–> {"Built-in Microphone", "Mobiola Headphone", "Mobiola Microphone", "Soundflower (2ch)", "Soundflower (64ch)"}

★Click Here to Open This Script 

Posted in Sound System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

mpSoundEngineで電話の呼び出し音のような音

Posted on 2月 17, 2018 by Takaaki Naganoya

外部フレームワーク(mpSoundEngine)を利用して電話の呼び出し音のような音を鳴らすAppleScriptです。

–> mpSoundKit.framework

AppleScript名:mpSoundEngineで電話の呼び出し音のような音
— Created 2017-12-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine

property engine : missing value

set engine to current application’s MPMonoSoundEngine’s alloc()’s init()
–https://pages.mtu.edu/~suits/notefreqs.html
set soundList to {440.0, 466.16}

repeat 10 times
  repeat with i in soundList
    makeSound(i) of me
  end repeat
end repeat

engine’s |stop|()

on makeSound(aHz)
  engine’s channel()’s setFrequency:aHz
  
engine’s start()
  
delay 0.05
  
–engine’s |stop|()
end makeSound

★Click Here to Open This Script 

Posted in Sound | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

mpSoundEngineで音階発生(Stereo)

Posted on 2月 17, 2018 by Takaaki Naganoya

外部フレームワーク(mpSoundEngine)を利用してステレオで(左右のチャンネルで別々の)音階の音を鳴らすAppleScriptです。

–> mpSoundKit.framework

AppleScript名:mpSoundEngineで音階発生(Stereo)
— Created 2017-12-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine

property engine : missing value

set engine to current application’s MPStereoSoundEngine’s alloc()’s init()
–https://pages.mtu.edu/~suits/notefreqs.html
set soundList to {261.63, 293.66, 329.63, 349.23, 392.0, 440.0, 493.88, 523.25}
set aLen to length of soundList

repeat with i from 1 to aLen
  makeStereoSound(item i of soundList, item (aLen – i + 1) of soundList) of me
end repeat

engine’s |stop|()

on makeStereoSound(aHz, bHz)
  engine’s leftChannel()’s setFrequency:aHz
  
engine’s rightChannel()’s setFrequency:bHz
  
engine’s start()
  
delay 0.5
end makeStereoSound

★Click Here to Open This Script 

Posted in Sound | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

mpSoundEngineで音階を出す

Posted on 2月 17, 2018 by Takaaki Naganoya

外部フレームワーク(mpSoundEngine)を利用して音階の音を鳴らすAppleScriptです。

–> mpSoundKit.framework

AppleScript名:mpSoundEngineで音階を出す
— Created 2017-12-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine
–http://piyocast.com/as/archives/5030

set engine to current application’s MPMonoSoundEngine’s alloc()’s init()
–https://pages.mtu.edu/~suits/notefreqs.html
set soundList to {261.63, 293.66, 329.63, 349.23, 392.0, 440.0, 493.88, 523.25}

engine’s start()

repeat with i in soundList
  (engine’s channel()’s setFrequency:i)
  
delay 0.1
end repeat

engine’s |stop|()

★Click Here to Open This Script 

Posted in Sound | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

mpSoundEngineでループ音声発生(サイレン2)

Posted on 2月 17, 2018 by Takaaki Naganoya

外部フレームワーク(mpSoundEngine)を利用してループでサイレンのような音声を鳴らすAppleScriptです。

–> mpSoundKit.framework

AppleScript名:mpSoundEngineでループ音声発生(サイレン2)
— Created 2017-12-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine
–http://piyocast.com/as/archives/5030

set engine to current application’s MPMonoSoundEngine’s alloc()’s init()
engine’s start()
repeat with i from 1000 to 100 by -20
  (engine’s channel()’s setFrequency:i)
  
delay 0.01
end repeat

engine’s |stop|()

★Click Here to Open This Script 

Posted in Sound | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

mpSoundEngineでループ音声発生(サイレン1)

Posted on 2月 17, 2018 by Takaaki Naganoya

外部フレームワーク(mpSoundEngine)を利用してループでサイレンのような音声を鳴らすAppleScriptです。

–> mpSoundKit.framework

AppleScript名:mpSoundEngineでループ音声発生(サイレン1)
— Created 2017-12-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine
–http://piyocast.com/as/archives/5030

set engine to current application’s MPMonoSoundEngine’s alloc()’s init()
engine’s start()

repeat with i from 100 to 1000 by 20
  repeat with ii from i to 1000 by 20
    (engine’s channel()’s setFrequency:ii)
    
delay 0.005
  end repeat
end repeat

engine’s |stop|()

★Click Here to Open This Script 

Posted in Sound | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

mpSoundEngineでランダム音発生(昔のSFでコンピュータが演算している風の音)

Posted on 2月 17, 2018 by Takaaki Naganoya

外部フレームワーク(mpSoundEngine)を利用して、ランダムに音(昔のSFでコンピュータが演算している風の音)を鳴らすAppleScriptです。

–> mpSoundKit.framework

AppleScript名:mpSoundEngineでランダム音発生(昔のSFでコンピュータが演算している風の音)
— Created 2017-12-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine

set engine to current application’s MPMonoSoundEngine’s alloc()’s init()

engine’s start()

repeat 100 times
  set aNum to random number from 50 to 4000
  (
engine’s channel()’s setFrequency:aNum)
  
delay 0.02
end repeat

engine’s |stop|()

★Click Here to Open This Script 

Posted in Sound | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

mpSoundEngineでA=440Hzのモノラルの音を出す

Posted on 2月 17, 2018 by Takaaki Naganoya

外部フレームワーク(mpSoundEngine)を利用して、440Hzの音を鳴らすAppleScriptです。

–> mpSoundKit.framework

AppleScript名:mpSoundEngineでA=440Hzのモノラルの音を出す
— Created 2017-12-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine
–http://piyocast.com/as/archives/5030

set engine to current application’s MPMonoSoundEngine’s alloc()’s init()
engine’s channel()’s setFrequency:440.0
engine’s start()
delay 3
engine’s |stop|()

★Click Here to Open This Script 

Posted in Sound | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

mpSoundEngineで8 octave分の音階発生

Posted on 2月 17, 2018 by Takaaki Naganoya

外部フレームワーク(mpSoundEngine)を利用して、8オクターブ分の音を鳴らすAppleScriptです。

–> mpSoundKit.framework

AppleScript名:mpSoundEngineで8 octave分の音階発生
— Created 2017-12-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine

property engine : missing value

–https://pages.mtu.edu/~suits/notefreqs.html
set soundList to {16.35, 17.32, 18.35, 19.45, 20.6, 21.83, 23.12, 24.5, 25.96, 27.5, 29.14, 30.87, 32.7, 34.65, 36.71, 38.89, 41.2, 43.65, 46.25, 49.0, 51.91, 55.0, 58.27, 61.74, 65.41, 69.3, 73.42, 77.78, 82.41, 87.31, 92.5, 98.0, 103.83, 110.0, 116.54, 123.47, 130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.0, 196.0, 207.65, 220.0, 233.08, 246.94, 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.0, 415.3, 440.0, 466.16, 493.88, 523.25, 554.37, 587.33, 622.25, 659.25, 698.46, 739.99, 783.99, 830.61, 880.0, 932.33, 987.77, 1046.5, 1108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760.0, 1864.66, 1975.53, 2093.0, 2217.46, 2349.32, 2489.02, 2637.02, 2793.83, 2959.96, 3135.96, 3322.44, 3520.0, 3729.31, 3951.07, 4186.01, 4434.92, 4698.63, 4978.03, 5274.04, 5587.65, 5919.91, 6271.93, 6644.88, 7040.0, 7458.62, 7902.13}

set revList to reverse of soundList

set engine to current application’s MPMonoSoundEngine’s alloc()’s init()

engine’s start()

repeat with i in soundList
  (engine’s channel()’s setFrequency:i)
  
delay 0.01
end repeat

repeat with i in revList
  (engine’s channel()’s setFrequency:i)
  
delay 0.01
end repeat

engine’s |stop|()

★Click Here to Open This Script 

Posted in Sound | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

TextEdit本文色に応じて青っぽい色は男性の音声で、赤っぽい色は女性の音声で読み上げ

Posted on 2月 16, 2018 by Takaaki Naganoya

TextEditの本文内で文字色が青っぽい色の文字は男性の音声で、赤っぽい色の文字は女性の音声で読み上げる(sayコマンド)AppleScriptです。

実行時には日本語読み上げ音声のKyokoとOtoyaをインストールしてある必要があります。インストールしてあるかどうか、対象の言語、性別で検出を行い、存在していなかった場合には読み上げを行いません。

AppleScript名:TextEdit本文色に応じて青っぽい色は男性の音声で、赤っぽい色は女性の音声で読み上げ
— Created 2018-02-15 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

property NSColor : a reference to current application’s NSColor
property NSArray : a reference to current application’s NSArray
property NSSortDescriptor : a reference to current application’s NSSortDescriptor

–TTS音声情報を取得する
set curLang to "ja_JP"

set v1List to getTTSVoiceNameWithLanguageAndGender(curLang, "Male") of me
if length of v1List = 0 then return
set v1 to contents of item 1 of v1List –Male Voice

set v2List to getTTSVoiceNameWithLanguageAndGender(curLang, "Female") of me
if length of v2List = 0 then return
set v2 to contents of item 1 of v2List –Female Voice

–TextEditの書類から情報を取得
set aResRec to (getTextStrAndColor() of me)
set colList to colorDat of aResRec
set strList to strList of aResRec

set aLen to length of strList

repeat with i from 1 to aLen
  set curColor to contents of item i of colList
  
set curStr to contents of item i of strList
  
set aColor to retColorDomainNameFromList(curColor, 65535) of me
  
  
if aColor = "blue" then
    –Read by Male Voice
    
say curStr using v1
  else if aColor = "red" then
    –Read by Female Voice  
    
say curStr using v2
  end if
  
end repeat

on getTextStrAndColor()
  tell application "TextEdit"
    if (count every document) = 0 then error "No Document"
    
    
tell front document
      set colList to (color of every attribute run)
      
set attList to every attribute run
    end tell
    
return {colorDat:colList, strList:attList}
  end tell
  
end getTextStrAndColor

on retCocoaColorList(aColorList, aMax)
  set cocoaColorList to {}
  
repeat with i in aColorList
    set the end of cocoaColorList to i / aMax
  end repeat
  
set the end of cocoaColorList to 1.0 –Alpha
  
return cocoaColorList
end retCocoaColorList

–数値の1D List with Recordをソート
on sort1DRecList(aList as list, aKey as string, ascendingF as boolean)
  set aArray to NSArray’s arrayWithArray:aList
  
set desc1 to NSSortDescriptor’s sortDescriptorWithKey:aKey ascending:ascendingF selector:"compare:"
  
set bList to (aArray’s sortedArrayUsingDescriptors:{desc1}) as list
  
return bList
end sort1DRecList

on getTTSVoiceNameWithLanguageAndGender(voiceLang, aGen)
  if aGen = "Male" then
    set aGender to "VoiceGenderMale"
  else if aGen = "Female" then
    set aGender to "VoiceGenderFemale"
  end if
  
  
set outArray to current application’s NSMutableArray’s new()
  
  
–Make Installed Voice List
  
set aList to current application’s NSSpeechSynthesizer’s availableVoices()
  
set bList to aList as list
  
  
repeat with i in bList
    set j to contents of i
    
set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j)
    (
outArray’s addObject:aDIc)
  end repeat
  
  
set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceLocaleIdentifier == %@ && VoiceGender== %@", voiceLang, aGender)
  
set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate
  
set aResList to (filteredArray’s valueForKey:"VoiceName") as list
  
  
return aResList
end getTTSVoiceNameWithLanguageAndGender

on retColorDomainNameFromList(aColList as list, aColMax as integer)
  set {rNum, gNum, bNum, aNum} to retCocoaColorList(aColList, aColMax) of me
  
set aCol to NSColor’s colorWithCalibratedRed:rNum green:gNum blue:bNum alpha:aNum
  
return retColorDomainNameFronNSColor(aCol) of me
end retColorDomainNameFromList

on retColorDomainNameFronNSColor(aCol)
  set hueVal to aCol’s hueComponent()
  
set satVal to aCol’s saturationComponent()
  
set brightVal to aCol’s brightnessComponent()
  
  
if satVal ≤ 0.01 then set satVal to 0.0
  
  
set colName to ""
  
  
if satVal = 0.0 then
    if brightVal ≤ 0.2 then
      set colName to "black"
    else if (brightVal > 0.95) then
      set colName to "white"
    else
      set colName to "gray"
    end if
  else
    if hueVal ≤ (15.0 / 360) or hueVal ≥ (330 / 360) then
      set colName to "red"
    else if hueVal ≤ (45.0 / 360) then
      set colName to "orange"
    else if hueVal < (70.0 / 360) then
      set colName to "yellow"
    else if hueVal < (150.0 / 360) then
      set colName to "green"
    else if hueVal < (190.0 / 360) then
      set colName to "light blue" –cyan
    else if (hueVal < 250.0 / 360.0) then
      set colName to "blue"
    else if (hueVal < 290.0 / 360.0) then
      set colName to "purple"
    else
      set colName to "pink" –magenta
    end if
  end if
  
  
return colName
end retColorDomainNameFronNSColor

★Click Here to Open This Script 

Posted in Color Sound Text | Tagged 10.11savvy 10.12savvy 10.13savvy Sorting TextEdit | Leave a comment

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • macOS 13, Ventura(継続更新)
  • アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3
  • UI Browserがgithub上でソース公開され、オープンソースに
  • Xcode 14.2でAppleScript App Templateを復活させる
  • macOS 13 TTS Voice環境に変更
  • 2022年に書いた価値あるAppleScript
  • ChatGPTで文章のベクトル化(Embedding)
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた
  • 従来と異なるmacOS 13の性格?
  • 新発売:CotEditor Scripting Book with AppleScript
  • macOS 13対応アップデート:AppleScript実践的テクニック集(1)GUI Scripting
  • AS関連データの取り扱いを容易にする(はずの)privateDataTypeLib
  • macOS 13でNSNotFoundバグふたたび
  • macOS 12.5.1、11.6.8でFinderのselectionでスクリーンショット画像をopenできない問題
  • ChatGPTでchatに対する応答文を取得
  • 新発売:iWork Scripting Book with AppleScript
  • Finderの隠し命令openVirtualLocationが発見される
  • macOS 13.1アップデートでスクリプトエディタの挙動がようやくまともに
  • あのコン過去ログビューワー(暫定版)

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (277) 12.0savvy (185) 13.0savvy (55) CotEditor (60) Finder (47) iTunes (19) Keynote (98) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (41) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (117) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (56) Pages (37) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) WKUserScriptInjectionTimeAtDocumentEnd (18) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • Clipboard
  • Code Sign
  • Color
  • Custom Class
  • dialog
  • drive
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • PDF
  • Peripheral
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC