调用 google speech api (使用Google语音识别引擎)

完全参考自:

http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/

http://aiku.me/bar/10448042

附:http://src.chromium.org/viewvc/chrome/trunk/src/content/browser/speech/

 

curl 命令行

curl -H "Content-Type: audio/x-flac; rate=8000" "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US" -F myfile="@org.flac" -k -o 'org_xx.txt'

 

wget 命令行

wget -O 'org_xx.txt' --user-agent="Mozilla/5.0" --post-file=org.flac --header="Content-Type: audio/x-flac; rate=8000" "http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US"

 

perl脚本  myspeech

 1 #! /usr/bin/perl
 2 require LWP::UserAgent;
 3 
 4 my $url = "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US";
 5 my $audio = "";
 6 
 7 open(FILE, "<" . $ARGV[0]);
 8 while(<FILE>)
 9 {
10      $audio .= $_;
11 }
12 close(FILE);
13 
14 my $ua = LWP::UserAgent->new;
15 
16 my $response = $ua->post($url, Content_Type => "audio/x-flac; rate=8000", Content => $audio);
17 
18 if ($response->is_success)
19 {
20      print $response->content;
21 }

运行方式  ./myspeech  org.flac

 

posted on 2014-03-06 12:12  阿加  阅读(3005)  评论(0编辑  收藏  举报

导航