screenreader / TTS linkage?

KildClient forum.
Post Reply
mt0neg
Posts: 1
Joined: Sun Dec 15, 2013 4:48 am

screenreader / TTS linkage?

Post by mt0neg »

I've been trying to use $hookdata to pipe text to espeak and other TTS engines but have had trouble getting it to work with multiple lines and lines followed by empty lines. Also I end up hearing the 0m at the end of every line. (presumably the hidden 'end line' character in mud protocol)
Does anyone have a script or link to plugins that work? The only links I've found so far are to the portugese one and I can't seem to get it to work. I e-mailed the coder a couple weeks back, but have had no response...
my current solution is
/use Clipboard
(with a copy of Clipboard.pm in usr/share/kildclient)
and

Hooks for 'OnReceivedText':
Num Ena Action
--- --- --------------------------------------------------------
0 y /Clipboard->copy($hookdata)
with
#!/bin/sh
while (sleep 1) do
[ "`xclip -o`" != "${LAST}" -a $DISPLAY ] && LAST=`xclip -o` && echo $LAST | speak -w /dev/stdout --stdin |aplay -
done
running in the bacround

it is hardly ideal...

Thank you for your consideration!
mt0neg@gmail.com
jmud
Posts: 19
Joined: Mon Jun 04, 2012 4:59 am

Re: screenreader / TTS linkage?

Post by jmud »

I wrote you a quick plugin. You should remove the hook you created, and add this plugin instead.

Let me know if it works, or not.

Code: Select all

package speaker;
#: Version: 1 
#: Description: Pipes received text to the system clipboard
#: Author: A S Lewis

use strict;
use diagnostics;
use warnings;

BEGIN {

    # Minimum standards for Perl
    require 5.008;

    use Clipboard;
}

# Add a hook event to capture text received from the mud
$::world->hook(
    'OnReceivedText' . '',                       # Hook event
    '/speaker->recvText("$hookdata");' . '',     # Action
    {
        name => 'speaker_hook',
    },
);

# Ready to go!
$::world->echonl('Speaker plugin ready to go!');

sub recvText {

    my ($plugin, $hookdata) = @_;

    # Local variables
    my @list;
    
    # Split $hookdata into lines (assuming it's not an empty string)
    if ($hookdata) {
        
        @list = split(/\n/, $hookdata);

        foreach my $line (@list) {

            # Strip ANSI codes from the line. The TTS engine obviously doesn't need them
            $line = ::stripansi($line);
                
            # Ignore empty lines and lines that don't contain any alphanumeric characters
            if (
                $line
                && ($line =~ m/[a-zA-Z0-9]/)
                # (If you want to ignore other kinds of line, you could add another Perl regex here)
            ) {
                # Send the line to the TTS engine
                Clipboard->copy($line);

                # Uncomment the following line to write to the terminal, too - if you want to check
                #   that the plugin is working the way you expect
#                print "line: $line\n";
            }
        }
    }
    
    # All my functions deliver a distinct return value ;)
    return 1;
}
Post Reply