我正在尝试使用 Python 播放音频文件。下面是我的代码:
from pygame import mixer
from time import sleep
from playsound import playsound
mixer.init()
# mixer.music.load("test1.mp3")
# mixer.music.play()
# sleep(1)
playsound("test.mp3")
我尝试了两种播放音频的方法:
- 播放声音
- 游戏
使用这两种方法,我都能够播放下面提到的音频。 https://drive.google.com/file/d/1-QQmMJnaK20L47DZGZS0MGZHnMK1uxdL/view?usp=sharing(文件名是welcome5.mp3)-->能玩
但无法播放下面给出的以下音频:
https://drive.google.com/file/d/1Mh8iMM026aSKaBD2iEUB9R5dceRcNa4w/view?usp=sharing(文件名为test.mp3)
使用 playsound 我收到以下错误:
Traceback (most recent call last):
File "c:\Users\SANKETH\PycharmProjects\Practice\Files\tests\test.py", line 9, in <module>
playsound("test.mp3")
File "C:\Users\SANKETH\AppData\Local\Programs\Python\Python38-32\lib\site-packages\playsound.py", line 35, in _playsoundWin
winCommand('open "' + sound + '" alias', alias)
File "C:\Users\SANKETH\AppData\Local\Programs\Python\Python38-32\lib\site-packages\playsound.py", line 31, in winCommand
raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
Error 277 for command:
open "test.mp3" alias playsound_0.8194752932436311
A problem occurred in initializing MCI.
在 pygame 的情况下,我收到以下错误:
Note: Illegal Audio-MPEG-Header 0x00000000 at offset 2650.
Note: Trying to resync...
Note: Skipped 10 bytes in input.
[d:\build\libmpg123\mpg123-1.25.10\src\libmpg123\layer1.c:30] error: Illegal bit allocation value.
[d:\build\libmpg123\mpg123-1.25.10\src\libmpg123\layer1.c:174] error: Aborting layer I decoding after step one.
以下是从 pip 安装的库或软件包的详细信息:
$ pip3 list|grep -i "playsound"
playsound 1.2.2
SANKETH@DESKTOP-ULOB0S7 MINGW64 ~/PycharmProjects/Practice/Files/tests (master)
$ pip3 list|grep -i "pygame"
pygame 1.9.6
names of the files:
$ ls -l|grep -i "test"
-rw-r--r-- 1 SANKETH 197121 9661986 Aug 31 02:55 test.mp3
-rw-r--r-- 1 SANKETH 197121 183 Aug 31 21:18 test.py
-rw-r--r-- 1 SANKETH 197121 1772 Aug 30 22:32 test.txt
-rw-r--r-- 1 SANKETH 197121 58890 Aug 31 03:14 test1.mp3