5

こんにちは、iOS 8 で AvSpeechSynthesizer を試した人はいますか? Xcode 6でクイックアプリを実行しましたが、音声が出ません。Xcode 5でも同じことを実行しましたが、問題なく動作しました。

http://nshipster.com/avspeechsynthesizer/のサンプル コード

NSString *string = @"Hello, World!";
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:string];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];

AVSpeechSynthesizer *speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
[speechSynthesizer speakUtterance:utterance];

Xcode6 のバグ?

==編集=== iOS 8 simのバグ/問題のように見えます.Xcode6のiOS7.1 Simは正常に動作します..

4

5 に答える 5

9

うん、それはバグです。iOS8 GM の時点で、AVSpeechSynthesizer に AVSpeechUtterance を話させる最初の試みは無音になるようです。

私の回避策は、AVSpeechSynthesizer が初期化された直後に 1 文字の発話を話すようにすることです。これは静かになり、その後、AVSpeechSynthesizer は通常どおり動作します。

AVSpeechUtterance *bugWorkaroundUtterance = [AVSpeechUtterance speechUtteranceWithString:@" "];
bugWorkaroundUtterance.rate = AVSpeechUtteranceMaximumSpeechRate;
[self.speechSynthesizer speakUtterance:bugWorkaroundUtterance];
于 2014-09-15T01:00:35.130 に答える
4

これは、8.0.2 (Xcode 6.0.1、iPad mini 1 でテスト中) ではまだ問題です。

これは、音声プロパティをデフォルトの方言以外のAVSpeechUtterance言語に設定している場合にのみ問題になります(私の場合、英語 (米国) がデフォルトです)。明確にするために、最初にデフォルト以外の言語で空のインスタンスを強制的に話すことで、問題を解決できます。その最後の部分は重要です。AVSpeechSynthesizerAVSpeechUtterance

以下は、修正を実装する単純なゲッターです。

- (AVSpeechUtterance *)utterance {
    if (!_utterance) {
        ...
        _utterance = [AVSpeechUtterance speechUtteranceWithString:@"hello world"];
        [_utterance setRate:0.2f];
        [_utterance setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:language]];

        // iOS 8 bug fix
        AVSpeechUtterance *dummyUtterance = [AVSpeechUtterance speechUtteranceWithString:@" "];
        [dummyUtterance setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:language]];
        [self.synthesizer speakUtterance:dummyUtterance];
    }
    return _utterance;
}
于 2014-10-23T14:41:17.160 に答える
1

これは確かに XCode 6 と iOS 8.0.2 のバグです。「voiceWithLanguage」プロパティを構成している限り、初めて文章を読み上げることはありません。したがって、現在の解決策は、最初に目的の言語で空の文字列を話すことです。

于 2014-10-09T16:50:00.133 に答える
0

私はこのクラスが問題を解決した(または少なくとも良い回避策である)ことを発見しました...

https://github.com/dale-moore/iOSTextToSpeech

于 2014-10-03T15:08:08.093 に答える