deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / osx / Speech.sc
blob2b78a23f86e404902b0b2bf6346f5a6335c3c27e
1 SpeechChannel{
2         var < channel, <pitch, <volume, <pitchMod, <voice, <rate;
3         var < wordDoneAction, < doneAction;
4         var < paused = false, isActive;
7         *new{|chan|
8                 ^super.newCopyArgs(chan);
9         }
11         wordDoneAction_{|action|
12                 Speech.wordDoneActions.put(channel, action)
13         }
15         doneAction_{|action|
16                 Speech.doneActions.put(channel, action)
17         }
19         pitch_{|midinote|
20                 pitch = midinote;
21                 Speech.setSpeechPitch(channel, pitch);
22         }
24         volume_{|amp|
25                 volume = amp;
26                 Speech.setSpeechVolume(channel, volume);
27         }
29         pitchMod_{|mod|
30                 pitchMod = mod;
31                 Speech.setSpeechPitchMod(channel, pitchMod);
32         }
34         rate_{|ratein|
35                 rate = ratein;
36                 Speech.setSpeechRate(channel, rate);
37         }
39         voice_{|num|
40                 voice = num;
41                 Speech.setSpeechVoice(channel, voice);
42         }
44         stop{|when=0|
45                 if(when.isNumber.not){
46                         when = Speech.stopMethods[when];
47                 };
48                 Speech.stop(channel, when);
49         }
51         pause{|bool|
52                 paused = bool;
53                 Speech.pause(channel, bool.binaryValue);
54         }
56         isActive{
57                 ^this.prIsActive(channel);
58         }
61         speak{|string, force=false|
62                 if(force.not){
63                         this.prSpeak(channel, string);
64                         ^this
65                 };
66                 r{
67                         this.stop(0);
68                         0.5.wait;
69                         this.prSpeak(channel, string);
70                 }.play
71         }
73         prSpeak{|channel, txt|
74                 _SpeakText
75         }
77         prIsActive{|chan|
78                 _SpeechVoiceIsSpeaking
79         }
83 Speech {
84         classvar <>wordActions, <>doneActions, <>wordAction, <>doneAction, <channels;
85         classvar <>initialized = false, <stopMethods;
87         *setSpeechVoice { arg chan,voice;
88                 _SetSpeechVoice
89         }
90         *setSpeechRate { arg chan,rate;
91                 _SetSpeechRate
92         }
93         *setSpeechPitch { arg chan,pitch;
94                 _SetSpeechPitch
95         }
96         *setSpeechPitchMod { arg chan,pitchMod;
97                 _SetSpeechPitchMod
98         }
99         *setSpeechVolume { arg chan,volume;
100                 _SetSpeechVolume
101         }
102         *pause { arg chan, paused=0;
103                 _SetSpeechPause
104         }
106         //when: 0 kImmediate, 1 kEndOfWord, 2 kEndOfSentence
107         *stop { arg chan, when=0;
108                 _SetSpeechStopAt
109         }
110         //private
111         *init { arg num= 1;
112                 initialized = true;
113                 channels = Array.new(num);
114                 wordActions = Array.newClear(num);
115                 doneActions =  Array.newClear(num);
116                 num.do{|i|
117                         channels.add(SpeechChannel(i))
118                 };
119                 stopMethods = (immediate: 0, endOfWord: 1, endOfSentence: 2);
120                 this.prInitSpeech
121         }
122         *prInitSpeech { arg num=16;
123                 _InitSpeech
124         }
125         *doWordAction { arg chan;
126                 wordAction.value(chan); //backward compatibility
127                 wordActions[chan].value(channels[chan]);
128         }
129         *doSpeechDoneAction { arg chan;
130                 doneAction.value(chan);
131                 doneActions[chan].value(channels[chan]);
132         }
135 //speech by jan trutzschler