Upload
-
View
62
Download
0
Embed Size (px)
Citation preview
Text-to-SpeechCocoa Study at Ikebukuro #4
Bitz Co., Ltd. 村上幸雄
Speech Synthesis
CocoaではNSSpeechSynthesizer *synthesizer = [[NSSpeechSynthesizer alloc] init];[synthesizer setDelegate:self];[synthesizer startSpeakingString:@"Hello, world."]; - (void)speehSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)finishedpeaking{ ...}
Core FoundationではSpeechChannel *chan;err = NewSpeechChannel(NULL, &chan);CFNumber *callback = CFNumberCreate(NULL, kCFNumberLongType, HighlightSpokenWord);err = SetSpeechProperty(chan, kSpeechWordCFCallBack, callback);err = SpeakCFString(chan, CFSTR("Hello, world."), NULL); void HighlightSpokenWord(SpeechChannel chan, SRefCo refCon, CFStringRef aString, CFRange wordRange){ ....}
AU Lab
Mastered for iTunes
http://www.apple.com/jp/itunes/mastered-for-itunes/
テキストを sayコマンドで読み上げる$ say -n : -f ./風琴と魚の町 .txt
AU Labを起動
AUNetReceiveを追加
接続
AUDistortionを選択
パラメータ調整
Text-to-Speech
SpeechSynthesis.h
/*------------------------------------------*//* AudioUnit constants - new in 10.5 *//*------------------------------------------*/enum { kAudioUnitSubType_SpeechSynthesis = 'ttsp', /* kAudioUnitType_Generator */ kAudioUnitProperty_Voice = 3330, /* Get/Set (VoiceSpec) */ kAudioUnitProperty_SpeechChannel = 3331 /* Get (SpeechChannel) */};
AUNode inputNode, effectNode, outputNode;
NewAUGraph(&_auGraph); AudioComponentDescription cd;cd.componentType = kAudioUnitType_Generator;cd.componentSubType = kAudioUnitSubType_SpeechSynthesis;cd.componentManufacturer = kAudioUnitManufacturer_Apple;cd.componentFlags = 0;cd.componentFlagsMask = 0;
AUGraphAddNode(_auGraph, &cd, &inputNode);
cd.componentType = kAudioUnitType_Effect;cd.componentSubType = kAudioUnitSubType_Delay;AUGraphAddNode(_auGraph, &cd, &effectNode);
cd.componentType = kAudioUnitType_Output;cd.componentSubType = kAudioUnitSubType_DefaultOutput;AUGraphAddNode(_auGraph, &cd, &outputNode);
AUGraphConnectNodeInput(_auGraph, inputNode, 0, effectNode, 0);AUGraphConnectNodeInput(_auGraph, effectNode, 0, outputNode, 0);
AUGraphOpen(_auGraph);AUGraphInitialize(_auGraph); AudioUnit generateAudioUnit;AUGraphNodeInfo(_auGraph, inputNode, NULL, &generateAudioUnit);SpeechChannel channel;UInt32 sz = sizeof(SpeechChannel);AudioUnitGetProperty(generateAudioUnit, kAudioUnitProperty_SpeechChannel,
kAudioUnitScope_Global, 0, &channel, &sz);
AUGraphStart(_auGraph);
SpeakCFString(channel, CFSTR("Hello, world."), NULL);
var inputNode: AUNode = 0var effectNode: AUNode = 0var outputNode: AUNode = 0
NewAUGraph(&auGraph);
var cd = AudioComponentDescription()cd.componentType = kAudioUnitType_Generatorcd.componentSubType = kAudioUnitSubType_SpeechSynthesiscd.componentManufacturer = kAudioUnitManufacturer_Applecd.componentFlags = 0cd.componentFlagsMask = 0
AUGraphAddNode(auGraph!, &cd, &inputNode)
cd.componentType = kAudioUnitType_Effectcd.componentSubType = kAudioUnitSubType_DelayAUGraphAddNode(auGraph!, &cd, &effectNode)
cd.componentType = kAudioUnitType_Outputcd.componentSubType = kAudioUnitSubType_DefaultOutputAUGraphAddNode(auGraph!, &cd, &outputNode)
AUGraphConnectNodeInput(auGraph!, inputNode, 0, effectNode, 0)AUGraphConnectNodeInput(auGraph!, effectNode, 0, outputNode, 0)
AUGraphOpen(auGraph!)AUGraphInitialize(auGraph!)
var generateAudioUnit: AudioUnit? = nilAUGraphNodeInfo(auGraph!, inputNode, nil, &generateAudioUnit)var channel: SpeechChannel? = nilvar sz: UInt32 = UInt32(MemoryLayout<SpeechChannel>.size)AudioUnitGetProperty(generateAudioUnit!, kAudioUnitProperty_SpeechChannel, kAudioUnitScope_Global, 0, &channel, &sz)
AUGraphStart(auGraph!)
SpeakCFString(channel!, "Nice to meet you. It's nice to see you! Nice meeting you. I'm pleased to meet you. Please say hello to your family. I look forward to seeing you again. Yes. Let's get together soon." as NSString, nil)