如何重复运行带参数的Python命令?

huangapple go评论85阅读模式
英文:

How do I run a python command with arguments repeatedly?

问题

我已经从Github上下载了一个Ubuntu/Python程序,用于从音频.wav文件生成Talkie语音文件(LPC)。
https://github.com/berrak/wav-files-to-arduino-talkie-lpc#python-language-installation
但问题是,我必须手动在命令行中执行它,因为它只允许一次处理一个文件。
我至少有43个文件要处理,所以这很慢。

我想将这个功能放入一个Python脚本中,该脚本会重复调用CLI,并将文件名列表附加到CLI。
我无法控制命令行中给出的参数。
CLI命令是python3 python_wizard -S -T tms5220 -f arduino ae.wav >> wavelpc.h

我需要将ae.wav文件更改为脚本中需要处理的文件。
我很乐意在脚本中重复相同的命令,并手动更改文件名为应该是的内容,但这在Python中不起作用。
但我已经尝试了一些各种网站上的建议,但没有成功。
我在Python中没有编程经验,所以有点迷茫!

我尝试了Rumpy过程,以及导入sys、subprocess,但都没有成功。
它只是出现了我不理解的错误。

英文:

I have downloaded a program from Github a Ubuntu/Python program to produce Talkie voice files (LPC) from Audio .wav files.
https://github.com/berrak/wav-files-to-arduino-talkie-lpc#python-language-installation
But the problem is that I have to manually do it from the CLI, as it only allows one file to be processed at a time.
I have at least 43 files to do, so this is SLOW.

I would like to put this into a python script that calls the CLI repeatedly with a list of files names attached to the CLI.
I have no control over the arguments given in the command line.
The CLI is python3 python_wizard -S -T tms5220 -f arduino ae.wav >> wavelpc.h

I need to change the ae.wav file to the files I need to process in the script.
I am quite happy to repeat the same command in the script, and manually change the file name to what it should be, but this does not work in python.
But I have tried some suggestions on various websites, but to no avail.
I have no programming experience in Python, so I am a bit lost!

I tried the Rumpy process, and the import sys, subprocess to no avail.
It just comes up with errors I don't understand.

答案1

得分: 0

我只有43个波形文件,它们与python_wizard在同一个目录中。... 如何让它重复调用所有CLI,包括设置?

如果目录中没有其他波形文件,您可以使用以下命令:

for file in *.wav
do  python3 python_wizard -S -T tms5220 -f arduino "$file"
done >> wavelpc.h

(如果您确实希望将输出附加到wavelpc.h,否则使用> wavelpc.h)。

英文:

>All I have is 43 wave files in the same directory as python_wizard. … How do I get it to call all the CLI including the setting repeatedly?

If there are no other wave files in the directory, you can

for file in *.wav
do  python3 python_wizard -S -T tms5220 -f arduino "$file"
done >>wavelpc.h

(if you really want to append the output to wavelpc.h - otherwise use >wavelpc.h).

答案2

得分: 0

我找到了答案,即使用一个BASH脚本。
原作者的建议是在开头包含一些Python命令,但当我去掉这些命令后,CLI命令现在能够运行,它获取每个文件名并执行调用python_wizard,更新文件,然后执行下一个命令。
命令的形式如下:

python3  /home/stephena/python_wizard/python_wizard -S -T tms5220 -f arduino ae.wav >> wavelpc.h

我更改了每行中.wav文件的文件名。
>> 是追加到文件而不是覆盖文件。
文件名是Fredall.sh
要执行它,我切换到python_wizard目录并运行以下命令:

bash Fredall.sh
英文:

I have found the answer which is to use a BASH script.
The Original advice from the author was to include some python commands at the beginning, but when I stripped these out, the CLI line now works and takes each file name and executes the call to python_wizard, updating the file and then executing the next command
The command is in the form of

python3  /home/stephena/python_wizard/python_wizard -S -T tms5220 -f arduino ae.wav >> wavelpc.h

I changed the filename of the .wav file on each line.
The >> adds to the file rather overwriting it.
The File name is Fredall.sh
and to execute it I change directory to the python_wizard directory and run the following command

bash Fredall.sh

huangapple
  • 本文由 发表于 2023年3月3日 18:36:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75625971.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定