dora-microphone 0.3.6__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
# Define the path to the README file relative to the package directory
|
4
|
+
readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md")
|
5
|
+
|
6
|
+
# Read the content of the README file
|
7
|
+
try:
|
8
|
+
with open(readme_path, "r", encoding="utf-8") as f:
|
9
|
+
__doc__ = f.read()
|
10
|
+
except FileNotFoundError:
|
11
|
+
__doc__ = "README file not found."
|
dora_microphone/main.py
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
import sounddevice as sd
|
2
|
+
import numpy as np
|
3
|
+
import pyarrow as pa
|
4
|
+
import time as tm
|
5
|
+
from enum import Enum
|
6
|
+
|
7
|
+
from dora import Node
|
8
|
+
|
9
|
+
|
10
|
+
class RecordingState(Enum):
|
11
|
+
"""Enum for recording states."""
|
12
|
+
|
13
|
+
PENDING = 0
|
14
|
+
RUNNING = 1
|
15
|
+
SILENCE = 2
|
16
|
+
|
17
|
+
|
18
|
+
def detect_speech(audio_data, threshold):
|
19
|
+
"""Check if the amplitude of the audio signal exceeds the threshold."""
|
20
|
+
return np.any(np.abs(audio_data) > threshold)
|
21
|
+
|
22
|
+
|
23
|
+
def main():
|
24
|
+
# Parameters
|
25
|
+
threshold = 500 # Threshold for detecting speech (adjust this as needed)
|
26
|
+
SAMPLE_RATE = 16000
|
27
|
+
silence_duration = 0.5 # Duration of silence before stopping the recording
|
28
|
+
|
29
|
+
# Initialize buffer and recording flag
|
30
|
+
buffer = []
|
31
|
+
state = RecordingState.PENDING
|
32
|
+
silence_start_time = tm.time()
|
33
|
+
node = Node()
|
34
|
+
|
35
|
+
# pylint: disable=unused-argument
|
36
|
+
def callback(indata, frames, time, status):
|
37
|
+
nonlocal buffer, state, silence_start_time, node
|
38
|
+
|
39
|
+
is_speaking = detect_speech(indata[:, 0], threshold)
|
40
|
+
if is_speaking:
|
41
|
+
if state == RecordingState.PENDING:
|
42
|
+
buffer = []
|
43
|
+
state = RecordingState.RUNNING
|
44
|
+
buffer.extend(indata[:, 0])
|
45
|
+
elif not is_speaking and state == RecordingState.RUNNING:
|
46
|
+
silence_start_time = tm.time() # Reset silence timer
|
47
|
+
buffer.extend(indata[:, 0])
|
48
|
+
state = RecordingState.SILENCE
|
49
|
+
elif not is_speaking and state == RecordingState.SILENCE:
|
50
|
+
if tm.time() - silence_start_time > silence_duration:
|
51
|
+
audio_data = np.array(buffer).ravel().astype(np.float32) / 32768.0
|
52
|
+
node.send_output("audio", pa.array(audio_data))
|
53
|
+
state = RecordingState.PENDING
|
54
|
+
else:
|
55
|
+
buffer.extend(indata[:, 0])
|
56
|
+
|
57
|
+
# Start recording
|
58
|
+
with sd.InputStream(
|
59
|
+
callback=callback, dtype=np.int16, channels=1, samplerate=SAMPLE_RATE
|
60
|
+
):
|
61
|
+
while True:
|
62
|
+
sd.sleep(int(100 * 1000))
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: dora-microphone
|
3
|
+
Version: 0.3.6
|
4
|
+
Summary: Dora dora-microphone
|
5
|
+
Home-page: https://github.com/dora-rs/dora.git
|
6
|
+
License: MIT
|
7
|
+
Author: Haixuan Xavier Tao
|
8
|
+
Author-email: tao.xavier@outlook.com
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Programming Language :: Python :: 2
|
11
|
+
Classifier: Programming Language :: Python :: 2.7
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Classifier: Programming Language :: Python :: 3.4
|
14
|
+
Classifier: Programming Language :: Python :: 3.5
|
15
|
+
Classifier: Programming Language :: Python :: 3.6
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
22
|
+
Requires-Dist: dora-rs (>=0.3.6,<0.4.0)
|
23
|
+
Requires-Dist: numpy (<2.0.0)
|
24
|
+
Requires-Dist: pyarrow (>=5.0.0)
|
25
|
+
Requires-Dist: sounddevice (>=0.4.6,<0.5.0)
|
26
|
+
Project-URL: Documentation, https://github.com/dora-rs/dora/blob/main/node-hub/dora-microphone/README.md
|
27
|
+
Description-Content-Type: text/markdown
|
28
|
+
|
29
|
+
# Dora Node for recording data from microphone
|
30
|
+
|
31
|
+
This node will send data as soon as the microphone volume is higher than a threshold.
|
32
|
+
|
33
|
+
Check example at [examples/speech-to-text](examples/speech-to-text)
|
34
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
dora_microphone/__init__.py,sha256=Gy4qL4vCeTyA5HR1Yp3ioL4-ClJyW8oi_38CzMuMsBM,358
|
2
|
+
dora_microphone/main.py,sha256=HA6PS9ki6T4REbiJ1GHE-BO1Ig2STASN-1Ji5g6mb1Y,1962
|
3
|
+
dora_microphone-0.3.6.dist-info/METADATA,sha256=tcB9JsOQvRtVjJytELzv-hDNT86aCpHdMGIZ_bI-IqQ,1360
|
4
|
+
dora_microphone-0.3.6.dist-info/WHEEL,sha256=IrRNNNJ-uuL1ggO5qMvT1GGhQVdQU54d6ZpYqEZfEWo,92
|
5
|
+
dora_microphone-0.3.6.dist-info/entry_points.txt,sha256=T7lmS26gTsxKwY0UAyR6GkjNDGYbyAFVzl94yMSePKc,61
|
6
|
+
dora_microphone-0.3.6.dist-info/RECORD,,
|