modify asr test
This commit is contained in:
parent
b69dd5a800
commit
30c2709e8c
@ -64,24 +64,25 @@ class SherpaNcnnAsr(AsrBase):
|
||||
self._notify_complete('介绍中国5000年历史文学')
|
||||
segment_id += 1
|
||||
time.sleep(60)
|
||||
#
|
||||
# with sd.InputStream(channels=1, dtype="float32", samplerate=self._sample_rate) as s:
|
||||
# while not self._stop_event.is_set():
|
||||
# samples, _ = s.read(self._samples_per_read) # a blocking read
|
||||
# samples = samples.reshape(-1)
|
||||
# self._recognizer.accept_waveform(self._sample_rate, samples)
|
||||
#
|
||||
# is_endpoint = self._recognizer.is_endpoint
|
||||
#
|
||||
# result = self._recognizer.text
|
||||
# if result and (last_result != result):
|
||||
# last_result = result
|
||||
# print("\r{}:{}".format(segment_id, result), end=".", flush=True)
|
||||
# self._notify_process(result)
|
||||
#
|
||||
# if is_endpoint:
|
||||
# if result:
|
||||
# print("\r{}:{}".format(segment_id, result), flush=True)
|
||||
# self._notify_complete(result)
|
||||
# segment_id += 1
|
||||
# self._recognizer.reset()
|
||||
'''
|
||||
with sd.InputStream(channels=1, dtype="float32", samplerate=self._sample_rate) as s:
|
||||
while not self._stop_event.is_set():
|
||||
samples, _ = s.read(self._samples_per_read) # a blocking read
|
||||
samples = samples.reshape(-1)
|
||||
self._recognizer.accept_waveform(self._sample_rate, samples)
|
||||
|
||||
is_endpoint = self._recognizer.is_endpoint
|
||||
|
||||
result = self._recognizer.text
|
||||
if result and (last_result != result):
|
||||
last_result = result
|
||||
print("\r{}:{}".format(segment_id, result), end=".", flush=True)
|
||||
self._notify_process(result)
|
||||
|
||||
if is_endpoint:
|
||||
if result:
|
||||
print("\r{}:{}".format(segment_id, result), flush=True)
|
||||
self._notify_complete(result)
|
||||
segment_id += 1
|
||||
self._recognizer.reset()
|
||||
'''
|
||||
|
36
test/test_asr_only.py
Normal file
36
test/test_asr_only.py
Normal file
@ -0,0 +1,36 @@
|
||||
#encoding = utf8
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
from asr import SherpaNcnnAsr
|
||||
|
||||
try:
|
||||
import sounddevice as sd
|
||||
except ImportError as e:
|
||||
print("Please install sounddevice first. You can use")
|
||||
print()
|
||||
print(" pip install sounddevice")
|
||||
print()
|
||||
print("to install it")
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
def main():
|
||||
print("Started! Please speak")
|
||||
asr = SherpaNcnnAsr()
|
||||
time.sleep(20)
|
||||
print("Stop! ")
|
||||
asr.stop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
devices = sd.query_devices()
|
||||
print(devices)
|
||||
default_input_device_idx = sd.default.device[0]
|
||||
print(f'Use default device: {devices[default_input_device_idx]["name"]}')
|
||||
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
print("\nCaught Ctrl + C. Exiting")
|
Loading…
Reference in New Issue
Block a user