Sox batch process under Debian

倾然丶 夕夏残阳落幕 提交于 2019-12-10 09:25:20

问题


I want to resample a bunch of wav files that I got on a folder.

My script is this:

for f in *.wav; do sox “$f” -r 48000 “${f%%%.wav}.wav”; done

The console give me this error: "sox FAIL formats: can't open input file `“90.wav”': No such file or directory" and so on with the 300 files that are placed on that folder.

How can I batch processing right this files? Why is it giving me this error?

Thanks a lot!

Solution:

for i in *wav; do echo $i; sox $i -r 48000 ${i%%.wav}r.wav; done

回答1:


Summary: It is the quote symbols

The problem is with the double-quotes:

for f in *.wav; do sox “$f” -r 48000 “${f%%%.wav}.wav”; done

The double-quotes above are non-standard. For them to be properly processed by the shell, the standard ASCII quote symbol must be used:

for f in ./*.wav; do sox "$f" -r 48000 "${f%%%.wav}.wav"; done

As an aside, note that ${f%%%.wav} removes any occurrences of %.wav from the end of the input file name. ${f%%%.wav}.wav adds one .wav back on to the end after removing any %.wav suffixes. You likely want something else here.

Verification

Using the bad quote characters, as per the question, observe the error message:

$ for f in *.wav; do sox “$f” -r 48000 “${f%%%.wav}.wav”; done
sox FAIL formats: can't open input file `“90.wav”': No such file or directory

Note the file name in the error message is shown with two-sets of quotes around the file name. This is what you saw as per the error message that in the question. The outer single-quotes are supplied by sox. The inner double-quotes are the funny quote characters provided on the command line. Because they are non-standard characters, the shell left them in place and passed them to the sox command.

While the file 90.wav exists, no file by the name of “90.wav” exists. Hence, the error.

Conclusion

Stick to standard ASCII characters for shell commands.

This issue can easily happen if the shell commands are typed in using a fancy word-processing editor that substitutes in typographically-pretty but non-standard characters. As tripleee points out, it can also happen when copying-and-pasting from the websites with inappropriate typographical styling.



来源:https://stackoverflow.com/questions/27264156/sox-batch-process-under-debian

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!