forked from NVIDIA/OpenSeq2Seq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_streaming_asr.py
57 lines (44 loc) · 1.31 KB
/
demo_streaming_asr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# from frame_asr import FrameASR
import numpy as np
import pyaudio as pa
import time
import pickle
CHANNELS = 1
RATE = 16000
DURATION = 2.0
CHUNK_SIZE = int(DURATION*RATE)
p = pa.PyAudio()
print('Available audio input devices:')
for i in range(p.get_device_count()):
dev = p.get_device_info_by_index(i)
if dev.get('maxInputChannels'):
print(i, dev.get('name'))
print('Please type input device ID:')
dev_idx = int(input())
# asr = FrameASR()
print('Initialization was successful')
data_list = []
def callback(in_data, frame_count, time_info, status):
signal = np.frombuffer(in_data, dtype=np.int16)
print(len(signal))
data_list.append(signal)
if len(data_list) == 20:
pickle.dump(data_list, open('data_list_demo_streaming.pickle', 'wb'))
print('Pickle File created ...')
pred = 'a'#asr.transcribe(signal)
if len(pred.strip()):
print('"{}"'.format(pred))
return (in_data, pa.paContinue)
stream = p.open(format=pa.paInt16,
channels=CHANNELS,
rate=RATE,
input=True,
input_device_index=dev_idx,
stream_callback=callback,
frames_per_buffer=CHUNK_SIZE)
stream.start_stream()
while stream.is_active():
time.sleep(0.1)
stream.stop_stream()
stream.close()
p.terminate()