Search code examples
c++macosspeechvoiceover

mac speech synthesis manager, when creating speech channel, returns Parameter error


I have a wrapper for many screen readers and speech systems on mac, windows, and linux, and the only one left to get working is mac. I have followed the examples found on the apple developer site for the speech synthesis manager, but I can't figure out the error I'm having. The error happens when I run the line of code

    OSErr val = NewSpeechChannel(NULL, chan);

However, this returns error -50, parameter error. I haven't been able to find any info regarding it and the speech synthesis manager, and have barely found any information on it at all, besides in help for programs themselves, instead of the sdk. I also looked on the speech synthesis manager reference under error codes, and it wasn't even listed. I've even asked on the apple developer forums, though the speech subforum seems rather dead.

So, what could cause an error -50 (parameter error), and how can it be fixed.

-Michael.

P.S. my code can be found in the following github project, under screen-reader/screen_reader.cpp, however I'm certain the only mac functions I've called at the point is the NewSpeechChannel, which throws error -50. http://github.com/2mb-solutions/horseshoes


Solution

  • Probably you do not allocate SpeechChannel structure which must be preallocated, you use NULL instead and that causes memory corruption.

    It should be

    SpeechChannel speechChannel;
    OSErr val = NewSpeechChannel(NULL, &chan);
    

    or

    SpeechChannel *speechChannel = malloc(sizeof(SpeechChannel)); // Not NULL
    OSErr val = NewSpeechChannel(NULL, chan);
    

    You can find example here