Chr*_*ris 5 api audio bash curl http
我正在尝试使用 curl 为允许传输/接收音频文件的 HTTP-API 发布音频数据。
首先我试过这个:
curl -vv --http1.0 -H "Content-Type: audio/basic" -H "Content-Length: 9999999" -H "Connection: Keep-Alive" -H "Cache-Control: no-cache" --data-binary @- 'http://IP/API-Endpoint.cgi'
Run Code Online (Sandbox Code Playgroud)
这似乎有效:
* Trying [IP]...
* TCP_NODELAY set
* Connected to [IP] ([IP]) port 80 (#0)
> POST /API-Endpoint.cgi HTTP/1.0
> Host: [IP]
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: audio/basic
> Content-Length: 9999999
> Connection: Keep-Alive
> Cache-Control: no-cache
>
* upload completely sent off: 17456 out of 17456 bytes
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/plain
< Content-Length: 0
* HTTP/1.0 connection set to keep alive!
< Connection: keep-alive
< Date: Wed, 06 Jun 2018 19:38:37 GMT
< Server: lighttpd/1.4.45
Run Code Online (Sandbox Code Playgroud)
但我只能听到音频文件的最后一部分。(该文件具有适用于 API 的正确音频格式:G.711 ?-law with 8000 Hz)我的下一个猜测是,音频传输速度太快,必须实时发送到 API 端点。于是我尝试了--limit-ratecurl的参数,没有效果。然后我尝试将具有速率限制的数据传输到 curl 中:
cat myfile.wav | pv -L 10k | curl -vv --http1.0 -H "Content-Type: audio/basic" -H "Content-Length: 9999999" -H "Connection: Keep-Alive" -H "Cache-Control: no-cache" --data-binary @- 'http://IP/API-Endpoint.cgi'
Run Code Online (Sandbox Code Playgroud)
但结果总是一样:我只能听到音频文件的最后一部分。似乎 curl 正在等待管道输入完成,然后像以前一样发送请求。
是否可以选择“实时”从 bash 将音频发布到 HTTP-API?
更新: 不强制 HTTP 1.0 我得到以下结果:
curl -vv -H "Content-Type: audio/basic" --data-binary '@myfile.wav' 'http://[IP]/API-Endpoint.cgi'
* Trying [IP]...
* TCP_NODELAY set
* Connected to [IP] ([IP]) port 80 (#0)
> POST /API-Endpoint.cgi HTTP/1.1
> Host: [IP]
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: audio/basic
> Content-Length: 15087
> Expect: 100-continue
>
< HTTP/1.1 417 Expectation Failed
< Content-Type: text/html
< Content-Length: 363
< Connection: close
< Date: Wed, 06 Jun 2018 20:34:22 GMT
< Server: lighttpd/1.4.45
<
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>417 - Expectation Failed</title>
</head>
<body>
<h1>417 - Expectation Failed</h1>
</body>
</html>
* Closing connection 0
Run Code Online (Sandbox Code Playgroud)
你-H "Content-Length: 9999999"说你的音频文件正好是 9999999 字节长(大约 10 兆字节),但curl 报告你的文件有 17456 字节:
* upload completely sent off: 17456 out of 17456 bytes
Run Code Online (Sandbox Code Playgroud)
(大约 0.02 兆字节),因此要么您的 Content-Length 标头错误(这是我最好的猜测),要么将音频文件提供给curl 的程序有故障,过早关闭标准输入。
要么修复您的内容长度标头,要么修复提供curl标准输入的程序,希望这应该完整地发送整个文件。
编辑:哦,似乎服务器无法处理Expect: 100-continue,要禁用该标头,请添加参数-H 'Expect:'
(空的 Expect 标头将使curl 完全省略标头,而不是将标头发送为空)
...但是要回答标题中的问题,是的,这就是论点--limit-rate。
| 归档时间: |
|
| 查看次数: |
1059 次 |
| 最近记录: |