Skip to content

Commit 64dcef6

Browse files
authored
Merge pull request #2 from yuma-m/feature/fix-player
Fix Player class
2 parents 5b344b9 + b50649f commit 64dcef6

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from setuptools import setup, find_packages
2-
version = '0.1.3'
2+
version = '0.1.4'
33

44
try:
55
import pypandoc

synthesizer/player.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
# -*- coding: utf-8 -*-
22

3-
import struct
4-
53
import numpy as np
64

75

86
class 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)

0 commit comments

Comments
 (0)