Skip to content

Commit 4db6543

Browse files
authored
Use pyaudio instead of sounddevice (#51)
* Use pyaudio instead of sounddevice * Change how config dict is merged. * Update version number in setup.py. * Update to version 2.
1 parent 68b8e6b commit 4db6543

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
symbl_rest >= 1.0.11
22
websocket-client >= 0.59.0
3-
sounddevice >= 0.4.1
3+
pyaudio ~= 0.2.12
44
numpy

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
setup(
2222
name="symbl",
23-
version="1.0.17",
23+
version="2.0.0",
2424
description="symbl.ai SDK",
2525
author_email="[email protected]",
2626
url="",
2727
keywords=["Symbl.ai SDK"],
28-
install_requires=["symbl_rest >= 1.0.11", "websocket-client >= 0.59.0", "sounddevice >= 0.4.1", "numpy"],
28+
install_requires=["symbl_rest >= 1.0.11", "websocket-client >= 0.59.0", "pyaudio ~= 0.2.12", "numpy"],
2929
packages=find_packages(),
3030
include_package_data=True,
3131
long_description="""\

symbl/streaming_api/StreamingApi.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from symbl import StreamingConnection
22
from symbl.configs.configs import SYMBL_STREAMING_API_FORMAT
33
from symbl.AuthenticationToken import get_access_token
4+
from symbl.utils import Helper
45
import websocket
56
import base64
67
import random
@@ -31,15 +32,19 @@ def start_connection(self, credentials=None, speaker=None, insight_types=None, c
3132
}
3233
}
3334

34-
for key in config.keys():
35-
config_object[key] = config[key]
35+
merged_config = Helper.merge_two_dicts(config_object, config)
36+
37+
# Merge subdictionary
38+
speechKey = 'speechRecognition'
39+
if speechKey in config:
40+
merged_config[speechKey] = Helper.merge_two_dicts(config_object[speechKey], config[speechKey])
3641

3742
start_request = {
3843
"type": "start_request",
3944
"insightTypes": [] if insight_types == None else [] if type(insight_types) != list else insight_types,
4045
"speaker": speaker,
4146
"trackers":trackers,
42-
"config": config_object
47+
"config": merged_config
4348
}
4449

4550
return StreamingConnection(url= url, connectionId=id, start_request=start_request)

symbl/streaming_api/StreamingConnection.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import websocket
88

9+
910
class StreamingConnection():
1011

1112
def __init__(self, url: str, connectionId: str, start_request: dict):
@@ -63,7 +64,11 @@ def send_audio(self, data):
6364

6465
@wrap_keyboard_interrupt
6566
def send_audio_from_mic(self, device=None):
66-
import sounddevice as sd
67-
with sd.InputStream(blocksize=4096, samplerate=44100, channels=1, callback= lambda indata, *args: self.send_audio(indata.copy().tobytes()), dtype='int16', device=device):
68-
while True:
69-
pass
67+
import pyaudio
68+
audio = pyaudio.PyAudio()
69+
chunk = 4096
70+
samplerate = self.start_request['config']['speechRecognition']['sampleRateHertz']
71+
stream = audio.open(format=pyaudio.paInt16, channels=1, rate=samplerate, input=True, frames_per_buffer=chunk)
72+
while True:
73+
data = stream.read(chunk)
74+
self.send_audio(data)

symbl/utils/Helper.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,10 @@ def parse_entity_response(api_response):
9595
entity_res[key]=val
9696
entity_response.append(entity_res)
9797

98-
return dict(entities=entity_response)
98+
return dict(entities=entity_response)
99+
100+
# Using copy because we support Python 3.4
101+
def merge_two_dicts(x, y):
102+
z = x.copy()
103+
z.update(y)
104+
return z

0 commit comments

Comments
 (0)