TypeError: expected str, bytes or os.PathLike object, not int in - subprocess
TypeError: expected str, bytes or os.PathLike object, not int in - subprocess
我正在使用音频编解码器并尝试压缩音频文件。为此,Linux 命令是
opusenc --bitrate 16 input_file.wav output_file.opus
现在运行这个命令我正在使用子进程,我的代码是
import subprocess
wav_file_path = '/home/mds-student/Documents/aDITYA/IEMOCAP/Ses01F_impro01.wav'
file_name = wav_file_path.split('.')[0]
file_name = os.path.basename(file_name)
bitrate = 16
cmd = ['opusenc', '--bitrate',bitrate ,wav_file_path, file_name, '.opus']
print(cmd)
subprocess.call(cmd)
这会引发错误
Traceback (most recent call last):
File "src/9_opus_conversion_files.py", line 78, in <module>
subprocess.call(cmd)
File "/home/mds-student/anaconda3/envs/venv/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/home/mds-student/anaconda3/envs/venv/lib/python3.6/subprocess.py", line 1295, in _execute_child
restore_signals, start_new_session, preexec_fn)
TypeError: expected str, bytes or os.PathLike object, not int
我做错了什么?
cmd
列表中的所有值在传递给 subprocess.call
之前应转换为字符串。
bitrate = 16
是一个整数,这就是错误发生的原因。
我正在使用音频编解码器并尝试压缩音频文件。为此,Linux 命令是
opusenc --bitrate 16 input_file.wav output_file.opus
现在运行这个命令我正在使用子进程,我的代码是
import subprocess
wav_file_path = '/home/mds-student/Documents/aDITYA/IEMOCAP/Ses01F_impro01.wav'
file_name = wav_file_path.split('.')[0]
file_name = os.path.basename(file_name)
bitrate = 16
cmd = ['opusenc', '--bitrate',bitrate ,wav_file_path, file_name, '.opus']
print(cmd)
subprocess.call(cmd)
这会引发错误
Traceback (most recent call last):
File "src/9_opus_conversion_files.py", line 78, in <module>
subprocess.call(cmd)
File "/home/mds-student/anaconda3/envs/venv/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/home/mds-student/anaconda3/envs/venv/lib/python3.6/subprocess.py", line 1295, in _execute_child
restore_signals, start_new_session, preexec_fn)
TypeError: expected str, bytes or os.PathLike object, not int
我做错了什么?
cmd
列表中的所有值在传递给 subprocess.call
之前应转换为字符串。
bitrate = 16
是一个整数,这就是错误发生的原因。