私は Xcode アプリを作成しています。ボタンを押してテキストを読み取れるようにする必要があります。誰かが IBAction ボタンの括弧内で使用する必要があるコード行を提供してくれれば、それは大歓迎です。ありがとうございました。
1170 次
1 に答える
7
これを試してください:
プロパティが必要です
@property(strong) NSSpeechSynthesizer *speechSynth;
あなたのinitメソッドで:
_speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
発言を開始するには:
- (IBAction)sayIt:(id)sender{
NSString *string = [self.textField stringValue];
// Is the string zero-length?
if ([string length] == 0) {
NSLog(@"string from %@ is of zero-length", self.textField);
return;
}
[self.speechSynth startSpeakingString:string];
NSLog(@"Have started to say: %@", string);
}
発言を停止するには:
- (IBAction)stopIt:(id)sender {
NSLog(@"stopping");
[self.speechSynth stopSpeaking];
}
于 2013-03-17T07:24:16.203 に答える