簡體   English   中英

如何循環 CURL 命令?

[英]How to for loop CURL commands?

我正在使用 Watson 的 Speech-To-Text Lite 服務,並試圖找到一種方法來自動加載新的音頻文件以進行轉錄。 我對 Bash 很陌生,所以我甚至不清楚更基本的術語 - 所以我發現這個問題很難找到解決方案。

對於單個用例,我運行以下文件(我的 API 密鑰省略了“MY APIKEY”)

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

我基本上想要實現的是克服手動輸入和重新輸入音頻文件和 output 的名稱。 因此,如果我有三個(或更多)音頻文件(即 audiofile_1、2 和 3.flac),我想創建一個與每個音頻文件相對應的 output 文件 - 一些可能有助於解釋我的意思的偽代碼

files = [file_1, file_2, file_3]

for file_x in files:
    run curl command
    save as output_x

你幾乎明白了。 你只需要學習一些 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命令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM