Text to-speech

17
Text-to-Speech Cocoa Study at Ikebukuro #4 Bitz Co., Ltd. 村村村村

Transcript of Text to-speech

Page 1: Text to-speech

Text-to-SpeechCocoa Study at Ikebukuro #4

Bitz Co., Ltd. 村上幸雄

Page 2: Text to-speech

Speech Synthesis

Page 3: Text to-speech
Page 4: Text to-speech

CocoaではNSSpeechSynthesizer *synthesizer = [[NSSpeechSynthesizer alloc] init];[synthesizer setDelegate:self];[synthesizer startSpeakingString:@"Hello, world."]; - (void)speehSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)finishedpeaking{ ...}

Page 5: Text to-speech

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){ ....}

Page 6: Text to-speech

AU Lab

Page 7: Text to-speech

Mastered for iTunes

http://www.apple.com/jp/itunes/mastered-for-itunes/

Page 8: Text to-speech

テキストを sayコマンドで読み上げる$ say -n : -f ./風琴と魚の町 .txt

Page 9: Text to-speech

AU Labを起動

Page 10: Text to-speech

AUNetReceiveを追加

Page 11: Text to-speech

接続

Page 12: Text to-speech

AUDistortionを選択

Page 13: Text to-speech

パラメータ調整

Page 14: Text to-speech

Text-to-Speech

Page 15: 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) */};

Page 16: Text to-speech

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);

Page 17: Text to-speech

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)