jtatum / colloquy-speech

Plugin for Colloquy IRC client which speaks the chat posted to a room using Apple text-to-speech
GNU General Public License v3.0
7 stars 6 forks source link

Queue up messages instead of interrupting #6

Open s4y opened 11 years ago

s4y commented 11 years ago

This should be totally doable by adding a delegate to be notified when the NSSpeechSynthesizer is finished speaking and by keeping a queue of messages to be spoken.

class SpeechDelegate(NSObject):
    def speechSynthesizer_didFinishSpeaking_(self, synthesizer, success):
        # ...

delegate = SpeechDelegate.new()
synthesizer.setDelegate_(delegate)

However, it looks like this breaks /reload plugins: the runtime complains about the new delegate class trying to replace the old one ("SpeechDelegate is overriding existing Objective-C class"). This StackOverflow answer discusses a tremendously unsupported workaround.

Can you think a way to get around that problem? I'd be happy to work on it, I'm just super unfamiliar with PyObjC, having never used it before.

jtatum commented 11 years ago

It's an interesting question. For my purposes, I kind of liked the interrupting behavior - when I fire this up, the channel I'm in tends to devolve to lots of spam. But I can definitely see the use.

Reading through the SO answer, I wonder if we use something like the decorator pattern? A function that returns a class which is passed to the setDelegate_ method, so it would be a new class each time rather than the same one? I'd have to poke at this a little, I guess. Interesting problem! Do you have a branch with the code you have so far?