我正在使用Watson的Speech- to -Text Lite服务,我正在尝试寻找一种方法来自动加载要转录的新音频文件。我对Bash非常陌生,所以我甚至连最基本的术语都不清楚-所以我发现这个问题很难找到解决方案。
对于单个用例,我运行以下文件(使用'MY APIKEY‘省略了我的API密钥)
curl -X POST -u "apikey: MY APIKEY" --header "Content-Type: audio/flac" --data-binary "@audiofile_1.flac" "https://gateway-lon.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_BroadbandModel&speaker_labels=true" > C:/Users/outputpath/output_1.txt
我基本上想要实现的是克服必须手动键入和重新键入音频文件和输出的名称。因此,如果我有三个(或更多)音频文件(即audiofile_1、2和3.flac),我想创建一个对应于每个音频文件的输出文件-一些伪代码,它可能有助于解释我的意思
files = [file_1, file_2, file_3]
for file_x in files:
run curl command
save as output_x
发布于 2019-10-14 15:31:05
你差一点就成功了。你只需要学习一些shell语法:
files=("file_1" "file_2" "file_3")
for file_x in "${files[@]}"
do
curl -X POST -u "apikey: MY APIKEY" --header "Content-Type: audio/flac" --data-binary "@${file_x}" "https://gateway-lon.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_BroadbandModel&speaker_labels=true" > "C:/Users/outputpath/${file_x}.txt"
done
首先,使用文件列表创建files
数组。然后,遍历这些文件并对每个文件运行curl
命令。
https://stackoverflow.com/questions/58379822
复制相似问题