IOMethods.py 文件源码

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

项目:ASP 作者: TUIlmenauAMS 项目源码 文件源码
def sound(x,fs):
        """ Plays a wave file using the pyglet library. But first, it has to be written.
            Termination of the playback is being performed by any keyboard input and Enter.
            Args:
            x:         (array) Floating point samples
            fs:        (int) The sampling rate
        """
        import pyglet as pg
        global player
        # Call the writing function
        AudioIO.wavWrite(x, fs, 16, 'testPlayback.wav')
        # Initialize playback engine
        player = pg.media.Player()
        # Initialize the object with the audio file
        playback = pg.media.load('testPlayback.wav')
        # Set it to player
        player.queue(playback)
        # Sound call
        player.play()
        # Killed by "keyboard"
        kill = raw_input()
        if kill or kill == '':
            AudioIO.stop()
        # Remove the dummy wave write
        os.remove('testPlayback.wav')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号