dora-microphone 0.3.6__tar.gz → 0.3.7rc1__tar.gz

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.
@@ -1,24 +1,21 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dora-microphone
3
- Version: 0.3.6
3
+ Version: 0.3.7rc1
4
4
  Summary: Dora dora-microphone
5
5
  Home-page: https://github.com/dora-rs/dora.git
6
6
  License: MIT
7
7
  Author: Haixuan Xavier Tao
8
8
  Author-email: tao.xavier@outlook.com
9
+ Requires-Python: >=3.7,<4.0
9
10
  Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Programming Language :: Python :: 2
11
- Classifier: Programming Language :: Python :: 2.7
12
11
  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
12
  Classifier: Programming Language :: Python :: 3.7
17
13
  Classifier: Programming Language :: Python :: 3.8
18
14
  Classifier: Programming Language :: Python :: 3.9
19
15
  Classifier: Programming Language :: Python :: 3.10
20
16
  Classifier: Programming Language :: Python :: 3.11
21
17
  Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
22
19
  Requires-Dist: dora-rs (>=0.3.6,<0.4.0)
23
20
  Requires-Dist: numpy (<2.0.0)
24
21
  Requires-Dist: pyarrow (>=5.0.0)
@@ -0,0 +1,36 @@
1
+ import sounddevice as sd
2
+ import numpy as np
3
+ import pyarrow as pa
4
+ import time as tm
5
+ import os
6
+
7
+ from dora import Node
8
+
9
+ MAX_DURATION = float(os.getenv("MAX_DURATION", "0.1"))
10
+ SAMPLE_RATE = int(os.getenv("SAMPLE_RATE", "16000"))
11
+
12
+
13
+ def main():
14
+ # Initialize buffer and recording flag
15
+ buffer = []
16
+ start_recording_time = tm.time()
17
+ node = Node()
18
+
19
+ # pylint: disable=unused-argument
20
+ def callback(indata, frames, time, status):
21
+ nonlocal buffer, node, start_recording_time
22
+
23
+ if tm.time() - start_recording_time > MAX_DURATION:
24
+ audio_data = np.array(buffer).ravel().astype(np.float32) / 32768.0
25
+ node.send_output("audio", pa.array(audio_data))
26
+ buffer = []
27
+ start_recording_time = tm.time()
28
+ else:
29
+ buffer.extend(indata[:, 0])
30
+
31
+ # Start recording
32
+ with sd.InputStream(
33
+ callback=callback, dtype=np.int16, channels=1, samplerate=SAMPLE_RATE
34
+ ):
35
+ while True:
36
+ sd.sleep(int(100 * 1000))
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dora-microphone"
3
- version = "0.3.6"
3
+ version = "0.3.7rc1"
4
4
  authors = [
5
5
  "Haixuan Xavier Tao <tao.xavier@outlook.com>",
6
6
  "Enzo Le Van <dev@enzo-le-van.fr>",
@@ -17,6 +17,7 @@ dora-rs = "^0.3.6"
17
17
  numpy = "< 2.0.0"
18
18
  pyarrow = ">= 5.0.0"
19
19
  sounddevice = "^0.4.6"
20
+ python = "^3.7"
20
21
 
21
22
  [tool.poetry.scripts]
22
23
  dora-microphone = "dora_microphone.main:main"
@@ -24,6 +25,3 @@ dora-microphone = "dora_microphone.main:main"
24
25
  [build-system]
25
26
  requires = ["poetry-core>=1.8.0"]
26
27
  build-backend = "poetry.core.masonry.api"
27
-
28
- [project]
29
- readme = "README.md"
@@ -1,62 +0,0 @@
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))