Pyglet无法播放.wav文件

时间:2016-07-07 18:35:37

标签: python playback pyglet

def morse_audio( item ):

    from pyglet import media
    import pyglet
    import time
    import glob
    import os
    import wave
    from contextlib import closing
    files = []
    audios = []
    for file in glob.glob('C:\\Users\\MQ\'s Virual World\\Downloads\\Morse\\*.wav'):
        ass = str(os.path.join('C:\\Users\MQ\'s Virual World\\Downloads\\Morse', file))
        print (ass)
        files.append(ass)
    #audio = media.load(files[1])
    #audio.play()
    #print (len(files))
    one = list(item)
    str_list = [x.strip(' ') for x in one]
    str_list = [x.strip('/') for x in str_list]

    for s in str_list[0]:
        if s != "-" and s !=  ".":
            list(item)
            for letter in item:
               for i in range(0, 51):
                    if letter == " ":
                        time.sleep(1.5)
                        audios.append("noise3.wav")
                        break
                    if letter != letterlst[i] and letter != letterlst[i].lower():
                        continue
                    else:
                        print (files[i])
                        audio = media.load(files[i])
                        audio.play()
                        audios.append(files[i])
                        audios.append("noise2.wav")
                        time.sleep(1)
        else:
            lst = item.split()
            print (' '.join(lst))
            for code in lst:
                for i in range(0, 51):
                    if code == "/":
                        time.sleep(1.5)
                        audios.append("noise3.wav")
                        break
                    if code != morse[i]:
                        continue
                    else:
                        print (files[i])
                        audio = media.load(files[i])
                        audio.play()
                        audios.append(files[i])
                        audios.append("noise2.wav")
                        time.sleep(1)
                        break
    outfile = "sounds.wav"

    data= []
    for file in audios:
        w = wave.open(file, 'rb')
        lol = w.getparams()
        print (lol)
        data.append( [w.getparams(), w.readframes(w.getnframes())] )
        w.close()

    with closing(wave.open(outfile, 'wb')) as output:

    # find sample rate from first file
        with closing(wave.open(audios[0])) as w:
            output.setparams(w.getparams())

    # write each file to output
        for audioo in audios:
            with closing(wave.open(audioo)) as w:
                output.writeframes(w.readframes(w.getnframes()))()))

所以这段代码以前有用,但是我想使用除了.wav文件之外的其他文件类型,但是因为它工作得很糟糕我回到了.wav。这些是不同的.wav文件,但之前工作的文件得到相同的错误消息。这是:

    Traceback (most recent call last):
  File "C:\Users\MQ's Virual World\AppData\Local\Programs\Python\Python35-32\morsecode.py", line 187, in <module>
    morse_audio("0123456789ÁÄ@&':,$=!-().+?;/_")
  File "C:\Users\MQ's Virual World\AppData\Local\Programs\Python\Python35-32\morsecode.py", line 96, in morse_audio
    audio.play()
  File "C:\Users\MQ's Virual World\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyglet\media\__init__.py", line 473, in play
    player.play()
  File "C:\Users\MQ's Virual World\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyglet\media\__init__.py", line 1012, in play
    self._set_playing(True)
  File "C:\Users\MQ's Virual World\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyglet\media\__init__.py", line 993, in _set_playing
    self._create_audio_player()
  File "C:\Users\MQ's Virual World\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyglet\media\__init__.py", line 1083, in _create_audio_player
    self._audio_player = audio_driver.create_audio_player(group, self)
  File "C:\Users\MQ's Virual World\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyglet\media\drivers\directsound\__init__.py", line 502, in create_audio_player
    return DirectSoundAudioPlayer(source_group, player)
  File "C:\Users\MQ's Virual World\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyglet\media\drivers\directsound\__init__.py", line 184, in __init__
    None)
  File "C:\Users\MQ's Virual World\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyglet\com.py", line 125, in <lambda>
    self.method.get_field()(self.i, self.name)(obj, *args)
  File "_ctypes/callproc.c", line 920, in GetResult
OSError: [WinError -2147024809] The parameter is incorrect

我已经尝试了过去工作的.wav文件。它在我使用.ogg文件时有效。也适用于mp3。似乎只有.wav文件给它带来问题。非常突然和随机。

0 个答案:

没有答案