我使用curl与IBM Watson一起制作成绩单,但我似乎无法得到一个输出,其中只有成绩单如下所示
另一种方法可能只是grep transcript":""
卷曲
curl -u user:password -X POST --header "Content-Type: audio/wav" --header "Transfer-Encoding: chunked" --data-binary @test.wav "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true" > demo.txt
{
"results": [
{
"alternatives": [
{
"confidence": 0.302,
"transcript": "when to stop announced "
}
],
"final": true
},
{
"alternatives": [
{
"confidence": 0.724,
"transcript": "Russia is destroying western cheese and considering a ban Weston condoms and infection internet is reacting "
}
],
"final": true
答案 0 :(得分:1)
要将输出存储到文件中,您可以使用选项-o
curl -u user:password -X POST --data-binary @test.wav
-o transcript.txt
--header "Content-Type: audio/wav" --header "Transfer-Encoding: chunked"
"https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true"
-o, --output <file>
将输出写入&lt; file&gt;而不是stdout。喜欢在:
curl http://ibm.com.com -o "html_output.txt"
答案 1 :(得分:0)
grep
无法满足您的要求,因为它不会比单行更精细。但是,grep
+ sed
可以用于在grep吐出的行上执行正则表达式替换。
grep的第一个管道:grep transcript
,然后管道到sed:sed 's/.*"transcript": "\(.*\)".*/\1/g'
这是完整的命令:
curl -u user:password -X POST --header "Content-Type: audio/wav" --header "Transfer-Encoding: chunked" --data-binary @test.wav "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true" | grep transcript | sed 's/.*"transcript": "\(.*\)".*/\1/g'
请注意,默认情况下,curl在管道输出时会显示几行状态。您可以使用-s:
禁用它们curl -s -u user:password -X POST --header "Content-Type: audio/wav" --header "Transfer-Encoding: chunked" --data-binary @test.wav "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true" | grep transcript | sed 's/.*"transcript": "\(.*\)".*/\1/g'
如果您有兴趣,请点击sed
的更多信息:http://www.grymoire.com/Unix/Sed.html
更新:我还应该提一下,如果您有兴趣做一些更复杂的事情,可以使用多种语言的SDK - https://github.com/watson-developer-cloud