This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// View all the voices | |
NSLog(@"%@", [AVSpeechSynthesisVoice speechVoices]); | |
/* Output | |
th-TH pt-BR sk-SK | |
fr-CA ro-RO no-NO | |
fi-FI pl-PL de-DE | |
nl-NL id-ID tr-TR | |
it-IT pt-PT fr-FR | |
ru-RU es-MX zh-HK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* If no voice is specified, the system's default will be used. */ | |
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Setting these values after a speech utterance has been enqueued will have no effect. */ | |
utterance.rate = AVSpeechUtteranceMaximumSpeechRate/2; // Values are pinned between AVSpeechUtteranceMinimumSpeechRate and AVSpeechUtteranceMaximumSpeechRate. | |
utterance.pitchMultiplier = 1.5; // [0.5 - 2] Default = 1 | |
utterance.volume = 0.5; // [0-1] Default = 1 | |
utterance.preUtteranceDelay = 1; // NSTimeInterval Default is 0.0 | |
utterance.postUtteranceDelay = 1; // NSTimeInterval Default is 0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance | |
{ | |
// Highlight the portion of text that will be spoken. | |
NSMutableAttributedString *aString = [[NSMutableAttributedString alloc] initWithString:_textLabel.text]; | |
[aString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:characterRange]; | |
_textLabel.attributedText = aString; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a synth | |
AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init]; | |
//create an utterance | |
AVSpeechUtterance* utterance = [AVSpeechUtterance speechUtteranceWithString:@"Hello World"]; | |
//Speak! | |
[synth speakUtterance:utterance]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; | |
NSString *filePath = [bundlePath stringByAppendingPathComponent:@"image.png"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString* string = @"Hello World"; | |
UIFont *font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:21]; | |
CGSize constraint = CGSizeMake(300,NSUIntegerMax); | |
NSDictionary *attributes = @{NSFontAttributeName: font}; | |
CGRect rect = [string boundingRectWithSize:constraint | |
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) |