Search code examples
perlibm-cloudspeech-recognitionasteriskspeech-to-text

How to use IBM Blumix Watson Speech to Text as speech engine on Asterisk


I followed the link below: http://zaf.github.io/asterisk-speech-recog/

Now I want to use IBM Blumix Watson Speech to Text instead of google speech-recog. Can anyone help me with this using the code provided on the link.

It is working using the google speech engine. but I want to use IBM Bluemix.

 #!/usr/bin/perl

use strict;
use warnings;

require LWP::UserAgent;
use WWW::Curl::Easy;

my $url = 'https://stream.watsonplatform.net/speech-to-text/api';

my $ua;
my $fh;
my $audio;
my $response;
my $headers;
my $username = 'username';
my $password = 'password';

local $ENV{'HTTPS_DEBUG'} = 1;
open($fh, "<", "test.flac") or die "Can't read file: $!";
$audio = do { local $/; <$fh> };
close($fh);

$ua = LWP::UserAgent->new;

$response = $ua->post($url, Content_Type => "audio/flac",Transfer_Encoding => "chunked", Content => $audio);
$response->authorization_basic($username, $password);
my $cont = $response->content;
print $cont;

Then it gave me output

SSL_connect:before/connect initialization
SSL_connect:SSLv2/v3 write client hello A
SSL_connect:SSLv3 read server hello A
SSL_connect:SSLv3 read server certificate A
SSL_connect:SSLv3 read server done A
SSL_connect:SSLv3 write client key exchange A
SSL_connect:SSLv3 write change cipher spec A
SSL_connect:SSLv3 write finished A
SSL_connect:SSLv3 flush data
SSL_connect:SSLv3 read finished A
500 write failed:

Solution

  • This works:

    curl -X POST -u uuuu:ppppp --header "Content-Type: audio/wav" --header "Transfer-Encoding: chunked" --data-binary @ira_47s_16khz.wav "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true"

    I am not familiar with Asterisk/Perl, however comparing the curl call with the code it seems that:

    • the host does not look right. With the right url you should begin to receive back the return messages and the error codes

    • the content type is slightly different

    • Can't find the data-binary chunk in the code. (it should be there however since your code works with Google api)