RealTimeSTT 0.1.8__tar.gz → 0.1.9__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Kolja Beigel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RealTimeSTT
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: A fast Voice Activity Detection and Transcription System
5
5
  Home-page: https://github.com/KoljaB/RealTimeSTT
6
6
  Author: Kolja Beigel
@@ -11,13 +11,14 @@ Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.6
13
13
  Description-Content-Type: text/markdown
14
+ License-File: LICENSE
14
15
  Requires-Dist: PyAudio==0.2.14
15
16
  Requires-Dist: faster-whisper==0.10.0
16
17
  Requires-Dist: pvporcupine==1.9.5
17
18
  Requires-Dist: webrtcvad==2.0.10
18
19
  Requires-Dist: halo==0.0.31
19
- Requires-Dist: torch==2.1.1
20
- Requires-Dist: torchaudio==2.1.1
20
+ Requires-Dist: torch==2.1.2
21
+ Requires-Dist: torchaudio==2.1.2
21
22
 
22
23
 
23
24
  # RealtimeSTT
@@ -37,6 +38,17 @@ https://github.com/KoljaB/RealtimeSTT/assets/7604638/207cb9a2-4482-48e7-9d2b-072
37
38
 
38
39
  ### Updates
39
40
 
41
+ #### v0.1.9
42
+ - switched to torch.multiprocessing
43
+ - added compute_type, input_device_index and gpu_device_index parameters
44
+ - recorder.text() interruptable with recorder.abort()
45
+ - fix for #20
46
+
47
+ #### v0.1.8
48
+ - added [example](https://github.com/KoljaB/RealtimeSTT/tree/master/example_browserclient) how to realtime transcribe from browser microphone
49
+ - large-v3 whisper model now supported (upgrade to faster_whisper 0.10.0)
50
+ - added feed_audio() and use_microphone parameter to feed chunks
51
+
40
52
  #### v0.1.7
41
53
  - Bugfix for Mac OS Installation (multiprocessing / queue.size())
42
54
  - KeyboardInterrupt handling (now abortable with CTRL+C)
@@ -47,7 +59,6 @@ https://github.com/KoljaB/RealtimeSTT/assets/7604638/207cb9a2-4482-48e7-9d2b-072
47
59
  - Bugfix for resource management in shutdown method
48
60
 
49
61
  #### v0.1.5
50
-
51
62
  - Bugfix for detection of short speech right after sentence detection (the problem mentioned in the video)
52
63
  - Main transcription and recording moved into separate process contexts with multiprocessing
53
64
 
@@ -200,6 +211,14 @@ recorder = AudioToTextRecorder(on_recording_start=my_start_callback,
200
211
  on_recording_stop=my_stop_callback)
201
212
  ```
202
213
 
214
+ ### Feed chunks
215
+
216
+ If you don't want to use the local microphone set use_microphone parameter to false and provide raw PCM audiochunks in 16-bit mono (samplerate 16000) with this method:
217
+
218
+ ```python
219
+ recorder.feed_audio(audio_chunk)
220
+ ```
221
+
203
222
  ### Shutdown
204
223
 
205
224
  You can shutdown the recorder safely by using the context manager protocol:
@@ -261,7 +280,13 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
261
280
  - Options: 'tiny', 'tiny.en', 'base', 'base.en', 'small', 'small.en', 'medium', 'medium.en', 'large-v1', 'large-v2'.
262
281
  - Note: If a size is provided, the model will be downloaded from the Hugging Face Hub.
263
282
 
264
- - **language** (str, default=""): Language code for transcription. If left empty, the model will try to auto-detect the language.
283
+ - **language** (str, default=""): Language code for transcription. If left empty, the model will try to auto-detect the language. Supported language codes are listed in [Whisper Tokenizer library](https://github.com/openai/whisper/blob/main/whisper/tokenizer.py).
284
+
285
+ - **compute_type** (str, default="default"): Specifies the type of computation to be used for transcription. See [Whisper Quantization](https://opennmt.net/CTranslate2/quantization.html)
286
+
287
+ - **input_device_index** (int, default=0): Audio Input Device Index to use.
288
+
289
+ - **gpu_device_index** (int, default=0): GPU Device Index to use. The model can also be loaded on multiple GPUs by passing a list of IDs (e.g. [0, 1, 2, 3]).
265
290
 
266
291
  - **on_recording_start**: A callable function triggered when recording starts.
267
292
 
@@ -273,6 +298,8 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
273
298
 
274
299
  - **ensure_sentence_ends_with_period** (bool, default=True): Ensures that every sentence that doesn't end with punctuation such as "?", "!" ends with a period
275
300
 
301
+ - **use_microphone** (bool, default=True): Usage of local microphone for transcription. Set to False if you want to provide chunks with feed_audio method.
302
+
276
303
  - **spinner** (bool, default=True): Provides a spinner animation text with information about the current recorder state.
277
304
 
278
305
  - **level** (int, default=logging.WARNING): Logging level.
@@ -16,6 +16,17 @@ https://github.com/KoljaB/RealtimeSTT/assets/7604638/207cb9a2-4482-48e7-9d2b-072
16
16
 
17
17
  ### Updates
18
18
 
19
+ #### v0.1.9
20
+ - switched to torch.multiprocessing
21
+ - added compute_type, input_device_index and gpu_device_index parameters
22
+ - recorder.text() interruptable with recorder.abort()
23
+ - fix for #20
24
+
25
+ #### v0.1.8
26
+ - added [example](https://github.com/KoljaB/RealtimeSTT/tree/master/example_browserclient) how to realtime transcribe from browser microphone
27
+ - large-v3 whisper model now supported (upgrade to faster_whisper 0.10.0)
28
+ - added feed_audio() and use_microphone parameter to feed chunks
29
+
19
30
  #### v0.1.7
20
31
  - Bugfix for Mac OS Installation (multiprocessing / queue.size())
21
32
  - KeyboardInterrupt handling (now abortable with CTRL+C)
@@ -26,7 +37,6 @@ https://github.com/KoljaB/RealtimeSTT/assets/7604638/207cb9a2-4482-48e7-9d2b-072
26
37
  - Bugfix for resource management in shutdown method
27
38
 
28
39
  #### v0.1.5
29
-
30
40
  - Bugfix for detection of short speech right after sentence detection (the problem mentioned in the video)
31
41
  - Main transcription and recording moved into separate process contexts with multiprocessing
32
42
 
@@ -179,6 +189,14 @@ recorder = AudioToTextRecorder(on_recording_start=my_start_callback,
179
189
  on_recording_stop=my_stop_callback)
180
190
  ```
181
191
 
192
+ ### Feed chunks
193
+
194
+ If you don't want to use the local microphone set use_microphone parameter to false and provide raw PCM audiochunks in 16-bit mono (samplerate 16000) with this method:
195
+
196
+ ```python
197
+ recorder.feed_audio(audio_chunk)
198
+ ```
199
+
182
200
  ### Shutdown
183
201
 
184
202
  You can shutdown the recorder safely by using the context manager protocol:
@@ -240,7 +258,13 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
240
258
  - Options: 'tiny', 'tiny.en', 'base', 'base.en', 'small', 'small.en', 'medium', 'medium.en', 'large-v1', 'large-v2'.
241
259
  - Note: If a size is provided, the model will be downloaded from the Hugging Face Hub.
242
260
 
243
- - **language** (str, default=""): Language code for transcription. If left empty, the model will try to auto-detect the language.
261
+ - **language** (str, default=""): Language code for transcription. If left empty, the model will try to auto-detect the language. Supported language codes are listed in [Whisper Tokenizer library](https://github.com/openai/whisper/blob/main/whisper/tokenizer.py).
262
+
263
+ - **compute_type** (str, default="default"): Specifies the type of computation to be used for transcription. See [Whisper Quantization](https://opennmt.net/CTranslate2/quantization.html)
264
+
265
+ - **input_device_index** (int, default=0): Audio Input Device Index to use.
266
+
267
+ - **gpu_device_index** (int, default=0): GPU Device Index to use. The model can also be loaded on multiple GPUs by passing a list of IDs (e.g. [0, 1, 2, 3]).
244
268
 
245
269
  - **on_recording_start**: A callable function triggered when recording starts.
246
270
 
@@ -252,6 +276,8 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
252
276
 
253
277
  - **ensure_sentence_ends_with_period** (bool, default=True): Ensures that every sentence that doesn't end with punctuation such as "?", "!" ends with a period
254
278
 
279
+ - **use_microphone** (bool, default=True): Usage of local microphone for transcription. Set to False if you want to provide chunks with feed_audio method.
280
+
255
281
  - **spinner** (bool, default=True): Provides a spinner animation text with information about the current recorder state.
256
282
 
257
283
  - **level** (int, default=logging.WARNING): Logging level.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RealTimeSTT
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: A fast Voice Activity Detection and Transcription System
5
5
  Home-page: https://github.com/KoljaB/RealTimeSTT
6
6
  Author: Kolja Beigel
@@ -11,13 +11,14 @@ Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.6
13
13
  Description-Content-Type: text/markdown
14
+ License-File: LICENSE
14
15
  Requires-Dist: PyAudio==0.2.14
15
16
  Requires-Dist: faster-whisper==0.10.0
16
17
  Requires-Dist: pvporcupine==1.9.5
17
18
  Requires-Dist: webrtcvad==2.0.10
18
19
  Requires-Dist: halo==0.0.31
19
- Requires-Dist: torch==2.1.1
20
- Requires-Dist: torchaudio==2.1.1
20
+ Requires-Dist: torch==2.1.2
21
+ Requires-Dist: torchaudio==2.1.2
21
22
 
22
23
 
23
24
  # RealtimeSTT
@@ -37,6 +38,17 @@ https://github.com/KoljaB/RealtimeSTT/assets/7604638/207cb9a2-4482-48e7-9d2b-072
37
38
 
38
39
  ### Updates
39
40
 
41
+ #### v0.1.9
42
+ - switched to torch.multiprocessing
43
+ - added compute_type, input_device_index and gpu_device_index parameters
44
+ - recorder.text() interruptable with recorder.abort()
45
+ - fix for #20
46
+
47
+ #### v0.1.8
48
+ - added [example](https://github.com/KoljaB/RealtimeSTT/tree/master/example_browserclient) how to realtime transcribe from browser microphone
49
+ - large-v3 whisper model now supported (upgrade to faster_whisper 0.10.0)
50
+ - added feed_audio() and use_microphone parameter to feed chunks
51
+
40
52
  #### v0.1.7
41
53
  - Bugfix for Mac OS Installation (multiprocessing / queue.size())
42
54
  - KeyboardInterrupt handling (now abortable with CTRL+C)
@@ -47,7 +59,6 @@ https://github.com/KoljaB/RealtimeSTT/assets/7604638/207cb9a2-4482-48e7-9d2b-072
47
59
  - Bugfix for resource management in shutdown method
48
60
 
49
61
  #### v0.1.5
50
-
51
62
  - Bugfix for detection of short speech right after sentence detection (the problem mentioned in the video)
52
63
  - Main transcription and recording moved into separate process contexts with multiprocessing
53
64
 
@@ -200,6 +211,14 @@ recorder = AudioToTextRecorder(on_recording_start=my_start_callback,
200
211
  on_recording_stop=my_stop_callback)
201
212
  ```
202
213
 
214
+ ### Feed chunks
215
+
216
+ If you don't want to use the local microphone set use_microphone parameter to false and provide raw PCM audiochunks in 16-bit mono (samplerate 16000) with this method:
217
+
218
+ ```python
219
+ recorder.feed_audio(audio_chunk)
220
+ ```
221
+
203
222
  ### Shutdown
204
223
 
205
224
  You can shutdown the recorder safely by using the context manager protocol:
@@ -261,7 +280,13 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
261
280
  - Options: 'tiny', 'tiny.en', 'base', 'base.en', 'small', 'small.en', 'medium', 'medium.en', 'large-v1', 'large-v2'.
262
281
  - Note: If a size is provided, the model will be downloaded from the Hugging Face Hub.
263
282
 
264
- - **language** (str, default=""): Language code for transcription. If left empty, the model will try to auto-detect the language.
283
+ - **language** (str, default=""): Language code for transcription. If left empty, the model will try to auto-detect the language. Supported language codes are listed in [Whisper Tokenizer library](https://github.com/openai/whisper/blob/main/whisper/tokenizer.py).
284
+
285
+ - **compute_type** (str, default="default"): Specifies the type of computation to be used for transcription. See [Whisper Quantization](https://opennmt.net/CTranslate2/quantization.html)
286
+
287
+ - **input_device_index** (int, default=0): Audio Input Device Index to use.
288
+
289
+ - **gpu_device_index** (int, default=0): GPU Device Index to use. The model can also be loaded on multiple GPUs by passing a list of IDs (e.g. [0, 1, 2, 3]).
265
290
 
266
291
  - **on_recording_start**: A callable function triggered when recording starts.
267
292
 
@@ -273,6 +298,8 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
273
298
 
274
299
  - **ensure_sentence_ends_with_period** (bool, default=True): Ensures that every sentence that doesn't end with punctuation such as "?", "!" ends with a period
275
300
 
301
+ - **use_microphone** (bool, default=True): Usage of local microphone for transcription. Set to False if you want to provide chunks with feed_audio method.
302
+
276
303
  - **spinner** (bool, default=True): Provides a spinner animation text with information about the current recorder state.
277
304
 
278
305
  - **level** (int, default=logging.WARNING): Logging level.
@@ -1,3 +1,4 @@
1
+ LICENSE
1
2
  README.md
2
3
  setup.py
3
4
  RealTimeSTT.egg-info/PKG-INFO
@@ -3,5 +3,5 @@ faster-whisper==0.10.0
3
3
  pvporcupine==1.9.5
4
4
  webrtcvad==2.0.10
5
5
  halo==0.0.31
6
- torch==2.1.1
7
- torchaudio==2.1.1
6
+ torch==2.1.2
7
+ torchaudio==2.1.2
@@ -26,7 +26,8 @@ Author: Kolja Beigel
26
26
 
27
27
  """
28
28
 
29
- from multiprocessing import Process, Pipe, Event, Manager
29
+ import torch.multiprocessing as mp
30
+ from typing import List, Union
30
31
  import faster_whisper
31
32
  import collections
32
33
  import numpy as np
@@ -43,6 +44,7 @@ import halo
43
44
  import time
44
45
  import os
45
46
  import re
47
+ import gc
46
48
 
47
49
  INIT_MODEL_TRANSCRIPTION = "tiny"
48
50
  INIT_MODEL_TRANSCRIPTION_REALTIME = "tiny"
@@ -74,6 +76,9 @@ class AudioToTextRecorder:
74
76
  def __init__(self,
75
77
  model: str = INIT_MODEL_TRANSCRIPTION,
76
78
  language: str = "",
79
+ compute_type: str = "default",
80
+ input_device_index: int = 0,
81
+ gpu_device_index: Union[int, List[int]] = 0,
77
82
  on_recording_start=None,
78
83
  on_recording_stop=None,
79
84
  on_transcription_start=None,
@@ -136,6 +141,16 @@ class AudioToTextRecorder:
136
141
  - language (str, default=""): Language code for speech-to-text engine.
137
142
  If not specified, the model will attempt to detect the language
138
143
  automatically.
144
+ - compute_type (str, default="default"): Specifies the type of
145
+ computation to be used for transcription.
146
+ See https://opennmt.net/CTranslate2/quantization.html.
147
+ - input_device_index (int, default=0): The index of the audio input
148
+ device to use.
149
+ - gpu_device_index (int, default=0): Device ID to use.
150
+ The model can also be loaded on multiple GPUs by passing a list of
151
+ IDs (e.g. [0, 1, 2, 3]). In that case, multiple transcriptions can
152
+ run in parallel when transcribe() is called from multiple Python
153
+ threads
139
154
  - on_recording_start (callable, default=None): Callback function to be
140
155
  called when recording of audio to be transcripted starts.
141
156
  - on_recording_stop (callable, default=None): Callback function to be
@@ -238,6 +253,9 @@ class AudioToTextRecorder:
238
253
  """
239
254
 
240
255
  self.language = language
256
+ self.compute_type = compute_type
257
+ self.input_device_index = input_device_index
258
+ self.gpu_device_index = gpu_device_index
241
259
  self.wake_words = wake_words
242
260
  self.wake_word_activation_delay = wake_word_activation_delay
243
261
  self.wake_word_timeout = wake_word_timeout
@@ -247,6 +265,7 @@ class AudioToTextRecorder:
247
265
  self.ensure_sentence_ends_with_period = (
248
266
  ensure_sentence_ends_with_period
249
267
  )
268
+ self.use_microphone = use_microphone
250
269
  self.min_gap_between_recordings = min_gap_between_recordings
251
270
  self.min_length_of_recording = min_length_of_recording
252
271
  self.pre_recording_buffer_duration = pre_recording_buffer_duration
@@ -272,8 +291,7 @@ class AudioToTextRecorder:
272
291
  self.allowed_latency_limit = ALLOWED_LATENCY_LIMIT
273
292
 
274
293
  self.level = level
275
- manager = Manager()
276
- self.audio_queue = manager.Queue()
294
+ self.audio_queue = mp.Queue()
277
295
  self.buffer_size = BUFFER_SIZE
278
296
  self.sample_rate = SAMPLE_RATE
279
297
  self.recording_start_time = 0
@@ -323,20 +341,30 @@ class AudioToTextRecorder:
323
341
  logger.addHandler(console_handler)
324
342
 
325
343
  self.is_shut_down = False
326
- self.shutdown_event = Event()
344
+ self.shutdown_event = mp.Event()
327
345
 
328
346
  logging.info("Starting RealTimeSTT")
329
347
 
330
- # Start transcription process
331
- self.interrupt_stop_event = Event()
332
- self.main_transcription_ready_event = Event()
333
- self.parent_transcription_pipe, child_transcription_pipe = Pipe()
334
-
335
- self.transcript_process = Process(
348
+ # Start transcription worker process
349
+ try:
350
+ # Only set the start method if it hasn't been set already
351
+ if mp.get_start_method(allow_none=True) is None:
352
+ mp.set_start_method("spawn")
353
+ except RuntimeError as e:
354
+ print("Start method has already been set. Details:", e)
355
+
356
+ self.interrupt_stop_event = mp.Event()
357
+ self.was_interrupted = mp.Event()
358
+ self.main_transcription_ready_event = mp.Event()
359
+ self.parent_transcription_pipe, child_transcription_pipe = mp.Pipe()
360
+
361
+ self.transcript_process = mp.Process(
336
362
  target=AudioToTextRecorder._transcription_worker,
337
363
  args=(
338
364
  child_transcription_pipe,
339
365
  model,
366
+ self.compute_type,
367
+ self.gpu_device_index,
340
368
  self.main_transcription_ready_event,
341
369
  self.shutdown_event,
342
370
  self.interrupt_stop_event
@@ -346,12 +374,13 @@ class AudioToTextRecorder:
346
374
 
347
375
  # Start audio data reading process
348
376
  if use_microphone:
349
- self.reader_process = Process(
377
+ self.reader_process = mp.Process(
350
378
  target=AudioToTextRecorder._audio_data_worker,
351
379
  args=(
352
380
  self.audio_queue,
353
381
  self.sample_rate,
354
382
  self.buffer_size,
383
+ self.input_device_index,
355
384
  self.shutdown_event,
356
385
  self.interrupt_stop_event
357
386
  )
@@ -366,7 +395,9 @@ class AudioToTextRecorder:
366
395
  )
367
396
  self.realtime_model_type = faster_whisper.WhisperModel(
368
397
  model_size_or_path=self.realtime_model_type,
369
- device='cuda' if torch.cuda.is_available() else 'cpu'
398
+ device='cuda' if torch.cuda.is_available() else 'cpu',
399
+ compute_type=self.compute_type,
400
+ device_index=self.gpu_device_index
370
401
  )
371
402
 
372
403
  except Exception as e:
@@ -473,12 +504,11 @@ class AudioToTextRecorder:
473
504
 
474
505
  logging.debug('RealtimeSTT initialization completed successfully')
475
506
 
476
- print(f"buffer_size: {self.buffer_size}")
477
- print(f"samplerate: {self.sample_rate}")
478
-
479
507
  @staticmethod
480
508
  def _transcription_worker(conn,
481
509
  model_path,
510
+ compute_type,
511
+ gpu_device_index,
482
512
  ready_event,
483
513
  shutdown_event,
484
514
  interrupt_stop_event):
@@ -499,6 +529,9 @@ class AudioToTextRecorder:
499
529
  for receiving audio data and sending transcription results.
500
530
  model_path (str): The path to the pre-trained faster_whisper model
501
531
  for transcription.
532
+ compute_type (str): Specifies the type of computation to be used
533
+ for transcription.
534
+ gpu_device_index (int): Device ID to use.
502
535
  ready_event (threading.Event): An event that is set when the
503
536
  transcription model is successfully initialized and ready.
504
537
  shutdown_event (threading.Event): An event that, when set,
@@ -516,7 +549,9 @@ class AudioToTextRecorder:
516
549
  try:
517
550
  model = faster_whisper.WhisperModel(
518
551
  model_size_or_path=model_path,
519
- device='cuda' if torch.cuda.is_available() else 'cpu'
552
+ device='cuda' if torch.cuda.is_available() else 'cpu',
553
+ compute_type=compute_type,
554
+ device_index=gpu_device_index
520
555
  )
521
556
 
522
557
  except Exception as e:
@@ -563,6 +598,7 @@ class AudioToTextRecorder:
563
598
  def _audio_data_worker(audio_queue,
564
599
  sample_rate,
565
600
  buffer_size,
601
+ input_device_index,
566
602
  shutdown_event,
567
603
  interrupt_stop_event):
568
604
  """
@@ -583,6 +619,7 @@ class AudioToTextRecorder:
583
619
  sample_rate (int): The sample rate of the audio input stream.
584
620
  buffer_size (int): The size of the buffer used in the audio
585
621
  input stream.
622
+ input_device_index (int): The index of the audio input device
586
623
  shutdown_event (threading.Event): An event that, when set, signals
587
624
  this worker method to terminate.
588
625
 
@@ -600,7 +637,8 @@ class AudioToTextRecorder:
600
637
  format=pyaudio.paInt16,
601
638
  channels=1,
602
639
  input=True,
603
- frames_per_buffer=buffer_size
640
+ frames_per_buffer=buffer_size,
641
+ input_device_index=input_device_index,
604
642
  )
605
643
 
606
644
  except Exception as e:
@@ -647,6 +685,20 @@ class AudioToTextRecorder:
647
685
  stream.close()
648
686
  audio_interface.terminate()
649
687
 
688
+ def wakeup(self):
689
+ """
690
+ If in wake work modus, wake up as if a wake word was spoken.
691
+ """
692
+ self.listen_start = time.time()
693
+
694
+ def abort(self):
695
+ self.start_recording_on_voice_activity = False
696
+ self.stop_recording_on_voice_deactivity = False
697
+ self._set_state("inactive")
698
+ self.interrupt_stop_event.set()
699
+ self.was_interrupted.wait()
700
+ self.was_interrupted.clear()
701
+
650
702
  def wait_audio(self):
651
703
  """
652
704
  Waits for the start and completion of the audio recording process.
@@ -671,7 +723,7 @@ class AudioToTextRecorder:
671
723
 
672
724
  # Wait until recording starts
673
725
  while not self.interrupt_stop_event.is_set():
674
- if self.start_recording_event.wait(timeout=0.5):
726
+ if self.start_recording_event.wait(timeout=0.02):
675
727
  break
676
728
 
677
729
  # If recording is ongoing, wait for voice inactivity
@@ -681,7 +733,7 @@ class AudioToTextRecorder:
681
733
 
682
734
  # Wait until recording stops
683
735
  while not self.interrupt_stop_event.is_set():
684
- if (self.stop_recording_event.wait(timeout=0.5)):
736
+ if (self.stop_recording_event.wait(timeout=0.02)):
685
737
  break
686
738
 
687
739
  # Convert recorded frames to the appropriate audio format.
@@ -756,9 +808,14 @@ class AudioToTextRecorder:
756
808
  str: The transcription of the recorded audio
757
809
  """
758
810
 
811
+ self.interrupt_stop_event.clear()
812
+ self.was_interrupted.clear()
813
+
759
814
  self.wait_audio()
760
815
 
761
816
  if self.is_shut_down or self.interrupt_stop_event.is_set():
817
+ if self.interrupt_stop_event.is_set():
818
+ self.was_interrupted.set()
762
819
  return ""
763
820
 
764
821
  if on_transcription_finished:
@@ -873,7 +930,8 @@ class AudioToTextRecorder:
873
930
 
874
931
  logging.debug('Terminating reader process')
875
932
  # Give it some time to finish the loop and cleanup.
876
- self.reader_process.join(timeout=10)
933
+ if self.use_microphone:
934
+ self.reader_process.join(timeout=10)
877
935
 
878
936
  if self.reader_process.is_alive():
879
937
  logging.warning("Reader process did not terminate "
@@ -896,6 +954,12 @@ class AudioToTextRecorder:
896
954
  if self.realtime_thread:
897
955
  self.realtime_thread.join()
898
956
 
957
+ if self.enable_realtime_transcription:
958
+ if self.realtime_model_type:
959
+ del self.realtime_model_type
960
+ self.realtime_model_type = None
961
+ gc.collect()
962
+
899
963
  def _recording_worker(self):
900
964
  """
901
965
  The main worker method which constantly monitors the audio
@@ -9,7 +9,7 @@ with open('requirements.txt') as f:
9
9
 
10
10
  setuptools.setup(
11
11
  name="RealTimeSTT",
12
- version="0.1.8",
12
+ version="0.1.9",
13
13
  author="Kolja Beigel",
14
14
  author_email="kolja.beigel@web.de",
15
15
  description="A fast Voice Activity Detection and Transcription System",
File without changes