gpt4 book ai didi

python - 使用 python 降低音频剪辑的音量时出错

转载 作者:太空宇宙 更新时间:2023-11-03 19:44:20 25 4
gpt4 key购买 nike

我尝试使用 pydub 降低或提高音频剪辑的音量。但是当我这样做时,出现以下错误。

 c:/Users/KalyanDk/vsprojects/Games/playsound.py
C:\Users\KalyanDk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\utils.py:165: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
C:\Users\KalyanDk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\utils.py:179: RuntimeWarning: Couldn't find ffplay or avplay - defaulting to ffplay, but may not work
warn("Couldn't find ffplay or avplay - defaulting to ffplay, but may not work", RuntimeWarning)
Traceback (most recent call last):
File "c:/Users/KalyanDk/vsprojects/Games/playsound.py", line 12, in <module>
play(louder_song)
File "C:\Users\KalyanDk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\playback.py", line 71, in play
_play_with_ffplay(audio_segment)
File "C:\Users\KalyanDk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\playback.py", line 18, in _play_with_ffplay
seg.export(f.name, "wav")
File "C:\Users\KalyanDk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\audio_segment.py", line 780, in export
out_f = _fd_or_path_or_tempfile(out_f, 'wb+')
File "C:\Users\KalyanDk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\utils.py", line 57, in _fd_or_path_or_tempfile
fd = open(fd, mode=mode)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\KalyanDk\\AppData\\Local\\Temp\\tmposf_nhdb.wav'

我无法理解出了什么问题。这是我的代码

from pydub import AudioSegment
from pydub.playback import play

song = AudioSegment.from_wav("Bounce.wav")

louder_song = song + 6

quieter_song = song - 3

play(louder_song)

louder_song.export("Bounce.wav", format='wav')'''

音频文件位于当前 python 文件所在的同一文件夹中。

最佳答案

尝试安装 simpleaudio:pip install simpleaudio

Pydub 在整个程序中多次使用 NamedTemporaryFile,包括在 play() 方法中。 NamedTemporaryFile 处理基本文件操作的方式在跨平台上存在一些明显的不一致。我相信 simpleaudio 将绕过在 play() 方法中调用 NamedTemporaryFile 的代码,尽管我不清楚这是否解决了 pydub 中 NamedTemporaryFile 的所有实例的问题。 Simpleaudio 确实为我解决了这个问题 - 不需要配置,只需安装即可。

引用: https://github.com/jiaaro/pydub/issues/343

关于python - 使用 python 降低音频剪辑的音量时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60234768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com