Speech::Recognition::Vosk - offline voice recognition using the Vosk toolkit
Most likely, you want to use the more convenient OO wrapper in Speech::Recognition::Vosk::Recognizer.
use Speech::Recognition::Vosk; use JSON 'decode_json'; my $model = Speech::Recognition::Vosk::model_new("model-en"); my $recognizer = Speech::Recognition::Vosk::recognizer_new($model, 44100); binmode STDIN, ':raw'; while( ! eof(*STDIN)) { read(STDIN, my $buf, 3200); my $complete = Speech::Recognition::Vosk::recognizer_accept_waveform($recognizer, $buf); my $spoken; if( $complete ) { $spoken = Speech::Recognition::Vosk::recognizer_result($recognizer); } else { $spoken = Speech::Recognition::Vosk::recognizer_partial_result($recognizer); } my $info = decode_json($spoken); if( $info->{text}) { print $info->{text},"\n"; } else { local $| = 1; print $info->{partial}, "\r"; }; } # Flush the buffers my $spoken = Speech::Recognition::Vosk::recognizer_final_result($recognizer); my $info = decode_json($spoken); print $info->{text},"\n";
To install Speech::Recognition::Vosk, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Speech::Recognition::Vosk
CPAN shell
perl -MCPAN -e shell install Speech::Recognition::Vosk
For more information on module installation, please visit the detailed CPAN module installation guide.