1

一部が時間を話すアプリを作っています。ただし、日付文字列(10/24/11など)をNSSpeechSynthesizerに渡すと、文字列として、「1、0、スラッシュ2、4、スラッシュ、1つ」、タイムスタンプと同じ「8つのコロン1つ1つ」と発音されます。コロンコロン」など。

NSSpeechSynthesizerのドキュメントを見て、phonemesFromTextメソッドを使用する必要があると思いますが、アプリに日時をスムーズに伝えるには、大変な作業のようです。より速い方法はありますか?

ありがとう

4

2 に答える 2

2

あなたはこのようなことを試すことができます:

@implementation MDAppController
- (id)init {
    if ((self = [super init])) {
    }
    return self;
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSDateFormatter *dateParser = [[[NSDateFormatter alloc]
        initWithDateFormat:@"%m/%d/%y" allowNaturalLanguage:YES] autorelease];

    NSDate *date = [dateParser dateFromString:@"10/24/11"];

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];

    [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
    [dateFormatter setDateStyle:NSDateFormatterLongStyle];

   NSString *string = [dateFormatter stringFromDate:date];

    NSLog(@"string == %@", string);
    // prints "October 24, 2011"

    NSSpeechSynthesizer *alex = [[NSSpeechSynthesizer alloc]
           initWithVoice:[NSSpeechSynthesizer defaultVoice]];
    [alex setDelegate:self];
    [alex startSpeakingString:string];
}

- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender
                   didFinishSpeaking:(BOOL)finishedSpeaking {
    if (finishedSpeaking) [sender autorelease];
}
@end

基本的に、これは2つのsを使用しています。1つは日付の文字列表現を実際のオブジェクトNSDateFormatterに「変換」し、もう1つはそれをより望ましい文字列表現に変換し直します。NSDateNSDate

dateParser明らかに、予想される入力文字列タイプに合うようにフォーマットを調整する必要があります。(できれば、文字列表現ではなく、入力日付を使用することもできます)。

于 2011-10-24T16:36:34.563 に答える
1

NSDateComponents to および -[NSString stringWithFormat:] を使用して、話し言葉を文字列として作成し、それを話しみませんか?

于 2011-10-24T14:33:31.987 に答える