python Kivy:[警告] [AudioSDL 2]无法加载bee-01a.wav:b '使用空源混合加载WAV_RW'

eqqqjvef  于 2023-01-29  发布在  Python
关注(0)|答案(1)|浏览(87)

我试着通过kivy播放声音,但一直无法工作。释放按钮时,方法似乎运行成功(即print语句运行,应用程序没有崩溃,也没有错误消息出现),但没有声音播放。查看kivy数据记录器后,标题中的警告显示。

from kivy.app import App

from kivy.core.audio import SoundLoader
from kivy.uix.boxlayout import BoxLayout

class Play(BoxLayout):
    sound_done = SoundLoader.load('beep-01a.wav')
    sound_finishing = SoundLoader.load('beep-07.wav')

    def play_sound_1(self):
        self.sound_finishing.play()
        print ("sound 1")
    def play_sound_2(self):
        self.sound_done.play()
        print ("sound 2")

class Sound(App):
    def build(self):
        p=Play()
        #p.start()
        return p

if __name__ == "__main__":
    Sound().run()

千伏

<BoxLayout>
    Button:
        text: "sound 1"
        on_release:
            root.play_sound_1()
    Button:
        text: "sound 2"
        on_release:
            root.play_sound_2()

数据记录

[INFO   ] [Logger      ] Record log in C:\Users\User\.kivy\logs\kivy_19- 
07-15_9.txt
[INFO   ] [Kivy        ] v1.11.0
[INFO   ] [Kivy        ] Installed at "C:\ProgramData\Anaconda3\lib\site- 
packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.7.1 (default, Dec 10 2018, 22:54:23) [MSC 
v.1915 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at 
"C:\ProgramData\Anaconda3\python.exe"
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, 
img_gif (img_ffpyplayer ignored)
[INFO   ] [Audio       ] Providers: audio_sdl2 (audio_ffpyplayer ignored)
[WARNING] Deprecated property "<AliasProperty name=filename>" of object " 
<kivy.core.audio.audio_sdl2.SoundSDL2 object at 0x0000028632B1CAD8>" was 
accessed, it will be removed in a future version
[WARNING] [AudioSDL2   ] Unable to load beep-01a.wav: b'Mix_LoadWAV_RW 
with NULL src'
[WARNING] [AudioSDL2   ] Unable to load beep-07.wav: b'Mix_LoadWAV_RW with 
NULL src'
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.5.13467 Compatibility Profile 
Context 21.19.414.1792'>
[INFO   ] [GL          ] OpenGL vendor <b'ATI Technologies Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'AMD Radeon R7 Graphics'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 5
[INFO   ] [GL          ] Shading version <b'4.50'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not 
docked
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available
sound 2
sound 2
sound 1
sound 1
[INFO   ] [WindowSDL   ] exiting mainloop and closing.
[INFO   ] [Base        ] Leaving application in progress...

Process finished with exit code 0

我试过使用wav,mp3和ogg的声音文件类型,但都没有工作。我已经坚持了很长一段时间,所以任何帮助将是非常感谢!谢谢

polhcujo

polhcujo1#

您提供的音频文件路径可能不正确。您只提供了文件名。
我,也有这个错误,并降落在这里...意识到的信息:
b '使用空源混合加载WAV_RW'
可能是说wav的路径在加载wav时为空-可能是找不到文件。
我通过在应用程序结构中更正wav文件的相对路径修复了这个错误。
例如,如果file.wav位于/app/data/file.wav,而主应用程序位于/app/www.example.com,则提供给SoundLoader. load()的路径应为"data/file.wav"。main.py, the path provided to SoundLoader.load() should be 'data/file.wav'.
如果使用os. path. join(abs,rel)添加解决方案,它可能会更具可移植性。
干杯。

相关问题