1

我试图弄清楚在SetSpeechProperty调用中使用的字典kSpeechCurrentVoiceProperty应该包含什么。我已经尝试了所有我能想到的方法来解决这个问题,但到目前为止我一直没有成功。这方面的文档(截至 10.8 版)没有说明。

这是我正在尝试做的代码示例:

OSStatus err = noErr;

SpeechChannel speechChannel = NULL;
NewSpeechChannel(NULL, &speechChannel);

id voiceID = ???; // From the crashes I got, I assume that this should be a NS/CFNumber.
id voiceCreator = ???;

CFDictionaryRef voiceDict = (CFDictionaryRef)@{
(NSString *)kSpeechVoiceID : voiceID,
(NSString *)kSpeechVoiceCreator : voiceCreator
};

err = SetSpeechProperty(speechChannel, kSpeechCurrentVoiceProperty, voiceDict);

理论上,我当然可以这样做:

VoiceSpec voice;
GetIndVoice(voiceNum, &voice);
NewSpeechChannel(&voice, &chan);

由于非常复杂的原因,这在我的具体情况下不是一个选择。实际上,我从其他我无法控制的地方获得了语音通道,我无法将其替换为另一个。所以我必须就地修改它。

请把我从这个记录不足的疯狂山谷中拯救出来!

4

1 回答 1

0

这对我有用(来自更新的CocoaSpeechSynthesisExample):

// Update our object fields with the selection
fSelectedVoiceCreator = theVoiceSpec.creator;
fSelectedVoiceID = theVoiceSpec.id;

// Change the current voice.  If it needs another engine, then dispose the current channel and open another
NSDictionary *voiceDict = @{(__bridge NSString *)kSpeechVoiceID:@(fSelectedVoiceID),
                            (__bridge NSString *)kSpeechVoiceCreator:@(fSelectedVoiceCreator)};

theErr = SetSpeechProperty(fCurSpeechChannel, kSpeechCurrentVoiceProperty, (__bridge CFDictionaryRef) voiceDict);
if (incompatibleVoice == theErr) {
    theErr = [self createNewSpeechChannel:&theVoiceSpec];
}
于 2015-06-06T03:00:37.787 回答