File tree Expand file tree Collapse file tree 3 files changed +10
-8
lines changed
Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 1+ ## 0.1.4
2+
3+ - Fix channels of Player class from 2 to 1 to play proper sound.
4+
15## 0.1.3
26
37- Specify audio output device.
Original file line number Diff line number Diff line change 11from setuptools import setup , find_packages
2- version = '0.1.3 '
2+ version = '0.1.4 '
33
44try :
55 import pypandoc
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22
3- import struct
4-
53import numpy as np
64
75
86class Player (object ):
97
10- def __init__ (self , channels = 2 , rate = 44100 ):
8+ def __init__ (self , rate = 44100 ):
119 try :
1210 import pyaudio
1311 self ._pyaudio = pyaudio .PyAudio ()
1412 self ._format = pyaudio .paInt16
1513 except ImportError :
1614 self ._pyaudio = None
1715 self ._stream = None
18- self ._channels = channels
16+ # TODO: support stereo channels
17+ self ._channels = 1
1918 self ._rate = rate
2019
2120 def enumerate_device (self ):
@@ -65,6 +64,5 @@ def play_wave(self, wave):
6564 """
6665 if not self ._stream :
6766 raise RuntimeError ("audio stream is not opened, please call open_stream() first." )
68- wave = (wave * float (2 ** 15 - 1 )).astype (np .int16 ).tolist ()
69- data = struct .pack ("h" * len (wave ), * wave )
70- self ._stream .write (data )
67+ wave = (wave * float (2 ** 15 - 1 )).astype (np .int16 ).tobytes ()
68+ self ._stream .write (wave )
You can’t perform that action at this time.
0 commit comments