Browse Source

Make microphone able to stop if there is a tick input

tags/v0.3.9-rc1
haixuantao 1 year ago
parent
commit
6691024b42
2 changed files with 11 additions and 2 deletions
  1. +2
    -0
      examples/speech-to-text/dataflow.yml
  2. +9
    -2
      node-hub/dora-microphone/dora_microphone/main.py

+ 2
- 0
examples/speech-to-text/dataflow.yml View File

@@ -2,6 +2,8 @@ nodes:
- id: dora-microphone
build: pip install -e ../../node-hub/dora-microphone
path: dora-microphone
inputs:
tick: dora/timer/millis/2000
outputs:
- audio



+ 9
- 2
node-hub/dora-microphone/dora_microphone/main.py View File

@@ -16,6 +16,8 @@ def main():
start_recording_time = tm.time()
node = Node()

always_none = node.next(timeout=0.001) is None

# pylint: disable=unused-argument
def callback(indata, frames, time, status):
nonlocal buffer, node, start_recording_time
@@ -32,5 +34,10 @@ def main():
with sd.InputStream(
callback=callback, dtype=np.int16, channels=1, samplerate=SAMPLE_RATE
):
while True:
sd.sleep(int(100 * 1000))
event_stream_is_none = False
while not event_stream_is_none:
if not always_none:
event = node.next()
event_stream_is_none = event is None
else:
sd.sleep(int(1000))

Loading…
Cancel
Save