使用timidity、ffmpeg和bash以编程方式将多个midi文件转换为wave

使用timidity、ffmpeg和bash以编程方式将多个midi文件转换为wave,bash,file-io,scripting,ffmpeg,midi,Bash,File Io,Scripting,Ffmpeg,Midi,我正试图构建一个脚本来按照标题所说的那样做,但我对Bash和其他在线资源有点不熟悉,它们只是非常有用 #! /bin/bash function inout #Create Function inout { output[0]=" " #Initialize variables input[0]=" " count=1 while [ "$count" -lt 10 ]; #Start loop to get all filenames do

我正试图构建一个脚本来按照标题所说的那样做,但我对Bash和其他在线资源有点不熟悉,它们只是非常有用

#! /bin/bash
function inout  #Create Function inout
{
    output[0]=" " #Initialize variables
    input[0]=" "
    count=1
    while [ "$count" -lt  10 ]; #Start loop to get all filenames
    do
        echo "Grabbing filename"             #User feedback

        input=$(ls | grep 0$count | grep MID | sed 's/ /\\ /g') #Grab filename
        #Replace ' ' character with '\ '
        output=$(echo $input | tr 'MID' 'mp3')
        #set output filename
        echo $count #Output variables for testing
        echo $input
        echo $output
        let count+=1 #Increment counter

        echo "converting $input to $output." #User feedback
        foo="timidity $input -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 320k $output"
        echo $foo
        #The last two lines are for the purpose of testing the full output
        #I can get the program to run if I copy and paste the output from above
        #but if I run it directly with the script it fails

    done
}

inout
我试图弄明白为什么不能从脚本内部运行它,为什么必须复制/粘贴$foo的输出


有什么想法吗?

无法从代码中分辨输入文件的名称;我将假定类似于宋的内容

inout () {
    for input in song_*.MID; do
        output=${input%.MID}.mp3
        timidity "$input" -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 320k "$output"
    done
}
它们的关键是定义一个合适的模式来匹配您的输入文件,然后使用
for
循环迭代匹配的文件


另外,您对
tr
的使用是不正确的:该调用会将
M
I
D
分别替换为
M
p
3
;它不会将出现的3个字符字符串
MID
替换为
mp3

歌曲标题01-Title.MID,但您的输入行可能会像*.MID一样工作。这比我的要干净得多。。。非常感谢。我得试试看,看它是否给了我同样的废话。