sound_linux.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Fuxenpruefung 作者: andb0t 项目源码 文件源码
def play_sound(sound):
    try:
        wf = wave.open(sound, 'rb')

        # instantiate PyAudio (1)
        p = pyaudio.PyAudio()

        # define callback (2)
        def callback(in_data, frame_count, time_info, status):
            data = wf.readframes(frame_count)
            return (data, pyaudio.paContinue)

        # open stream using callback (3)
        stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                        channels=wf.getnchannels(),
                        rate=wf.getframerate(),
                        output=True,
                        stream_callback=callback)

        # start the stream (4)
        stream.start_stream()
    except wave.Error:
        print('Warning: caught wave.Error!')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号