Macos 正在获取SetSpeechProperty以使用kSpeechCurrentVoiceProperty

Macos 正在获取SetSpeechProperty以使用kSpeechCurrentVoiceProperty,macos,text-to-speech,Macos,Text To Speech,我试图找出kSpeechCurrentVoiceProperty调用中使用的字典应该包含什么内容。我已经尝试了我能想到的所有方法来解决这个问题,但到目前为止我一直没有成功。这方面的文档(从10.8开始)没有说明 下面是我正在尝试执行的代码示例: OSStatus err = noErr; SpeechChannel speechChannel = NULL; NewSpeechChannel(NULL, &speechChannel); id voiceID = ???; // Fr

我试图找出
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);
由于非常复杂的原因,在我的具体案例中,这不是一个选项。事实上,我从其他地方获得了我无法控制的speechChannel,我无法用另一个代替它。所以我必须在原地修改它

请把我从这个没有记录的疯狂山谷中救出来

这对我来说很有效(从更新的版本):

// 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];
}