RealTimeSTT 0.2.3__tar.gz → 0.2.4__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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RealtimeSTT
3
- Version: 0.2.3
3
+ Version: 0.2.4
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
@@ -341,6 +341,8 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
341
341
 
342
342
  - **enable_realtime_transcription** (bool, default=False): Enables or disables real-time transcription of audio. When set to True, the audio will be transcribed continuously as it is being recorded.
343
343
 
344
+ - **use_main_model_for_realtime** (bool, default=False): If set to True, the main transcription model will be used for both regular and real-time transcription. If False, a separate model specified by `realtime_model_type` will be used for real-time transcription. Using a single model can save memory and potentially improve performance, but may not be optimized for real-time processing. Using separate models allows for a smaller, faster model for real-time transcription while keeping a more accurate model for final transcription.
345
+
344
346
  - **realtime_model_type** (str, default="tiny"): Specifies the size or path of the machine learning model to be used for real-time transcription.
345
347
  - Valid options: 'tiny', 'tiny.en', 'base', 'base.en', 'small', 'small.en', 'medium', 'medium.en', 'large-v1', 'large-v2'.
346
348
 
@@ -316,6 +316,8 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
316
316
 
317
317
  - **enable_realtime_transcription** (bool, default=False): Enables or disables real-time transcription of audio. When set to True, the audio will be transcribed continuously as it is being recorded.
318
318
 
319
+ - **use_main_model_for_realtime** (bool, default=False): If set to True, the main transcription model will be used for both regular and real-time transcription. If False, a separate model specified by `realtime_model_type` will be used for real-time transcription. Using a single model can save memory and potentially improve performance, but may not be optimized for real-time processing. Using separate models allows for a smaller, faster model for real-time transcription while keeping a more accurate model for final transcription.
320
+
319
321
  - **realtime_model_type** (str, default="tiny"): Specifies the size or path of the machine learning model to be used for real-time transcription.
320
322
  - Valid options: 'tiny', 'tiny.en', 'base', 'base.en', 'small', 'small.en', 'medium', 'medium.en', 'large-v1', 'large-v2'.
321
323
 
@@ -107,6 +107,7 @@ class AudioToTextRecorder:
107
107
 
108
108
  # Realtime transcription parameters
109
109
  enable_realtime_transcription=False,
110
+ use_main_model_for_realtime=False,
110
111
  realtime_model_type=INIT_MODEL_TRANSCRIPTION_REALTIME,
111
112
  realtime_processing_pause=INIT_REALTIME_PROCESSING_PAUSE,
112
113
  on_realtime_transcription_update=None,
@@ -206,6 +207,15 @@ class AudioToTextRecorder:
206
207
  - enable_realtime_transcription (bool, default=False): Enables or
207
208
  disables real-time transcription of audio. When set to True, the
208
209
  audio will be transcribed continuously as it is being recorded.
210
+ - use_main_model_for_realtime (str, default=False):
211
+ If True, use the main transcription model for both regular and
212
+ real-time transcription. If False, use a separate model specified
213
+ by realtime_model_type for real-time transcription.
214
+ Using a single model can save memory and potentially improve
215
+ performance, but may not be optimized for real-time processing.
216
+ Using separate models allows for a smaller, faster model for
217
+ real-time transcription while keeping a more accurate model for
218
+ final transcription.
209
219
  - realtime_model_type (str, default="tiny"): Specifies the machine
210
220
  learning model to be used for real-time transcription. Valid
211
221
  options include 'tiny', 'tiny.en', 'base', 'base.en', 'small',
@@ -363,6 +373,7 @@ class AudioToTextRecorder:
363
373
  self.on_recorded_chunk = on_recorded_chunk
364
374
  self.on_transcription_start = on_transcription_start
365
375
  self.enable_realtime_transcription = enable_realtime_transcription
376
+ self.use_main_model_for_realtime = use_main_model_for_realtime
366
377
  self.realtime_model_type = realtime_model_type
367
378
  self.realtime_processing_pause = realtime_processing_pause
368
379
  self.on_realtime_transcription_update = (
@@ -414,6 +425,7 @@ class AudioToTextRecorder:
414
425
  self.detected_language_probability = 0
415
426
  self.detected_realtime_language = None
416
427
  self.detected_realtime_language_probability = 0
428
+ self.transcription_lock = threading.Lock()
417
429
 
418
430
  # Initialize the logging configuration with the specified level
419
431
  log_format = 'RealTimeSTT: %(name)s - %(levelname)s - %(message)s'
@@ -493,7 +505,7 @@ class AudioToTextRecorder:
493
505
  )
494
506
 
495
507
  # Initialize the realtime transcription model
496
- if self.enable_realtime_transcription:
508
+ if self.enable_realtime_transcription and not self.use_main_model_for_realtime:
497
509
  try:
498
510
  logging.info("Initializing faster_whisper realtime "
499
511
  f"transcription model {self.realtime_model_type}"
@@ -967,19 +979,26 @@ class AudioToTextRecorder:
967
979
  """
968
980
  self._set_state("transcribing")
969
981
  audio_copy = copy.deepcopy(self.audio)
970
- self.parent_transcription_pipe.send((self.audio, self.language))
971
- status, result = self.parent_transcription_pipe.recv()
972
982
 
973
- self._set_state("inactive")
974
- if status == 'success':
975
- segments, info = result
976
- self.detected_language = info.language if info.language_probability > 0 else None
977
- self.detected_language_probability = info.language_probability
978
- self.last_transcription_bytes = audio_copy
979
- return self._preprocess_output(segments)
980
- else:
981
- logging.error(result)
982
- raise Exception(result)
983
+
984
+ with self.transcription_lock:
985
+ try:
986
+ self.parent_transcription_pipe.send((self.audio, self.language))
987
+ status, result = self.parent_transcription_pipe.recv()
988
+
989
+ self._set_state("inactive")
990
+ if status == 'success':
991
+ segments, info = result
992
+ self.detected_language = info.language if info.language_probability > 0 else None
993
+ self.detected_language_probability = info.language_probability
994
+ self.last_transcription_bytes = audio_copy
995
+ return self._preprocess_output(segments)
996
+ else:
997
+ logging.error(f"Transcription error: {result}")
998
+ raise Exception(result)
999
+ except Exception as e:
1000
+ logging.error(f"Error during transcription: {str(e)}")
1001
+ raise e
983
1002
 
984
1003
  def _process_wakeword(self, data):
985
1004
  """
@@ -1452,17 +1471,41 @@ class AudioToTextRecorder:
1452
1471
  audio_array = audio_array.astype(np.float32) / \
1453
1472
  INT16_MAX_ABS_VALUE
1454
1473
 
1455
- # Perform transcription and assemble the text
1456
- segments, info = self.realtime_model_type.transcribe(
1457
- audio_array,
1458
- language=self.language if self.language else None,
1459
- beam_size=self.beam_size_realtime,
1460
- initial_prompt=self.initial_prompt,
1461
- suppress_tokens=self.suppress_tokens,
1462
- )
1474
+ if self.use_main_model_for_realtime#:
1475
+ with self.transcription_lock:
1476
+ try:
1477
+ self.parent_transcription_pipe.send((audio_array, self.language))
1478
+ if self.parent_transcription_pipe.poll(timeout=5): # Wait for 5 seconds
1479
+ status, result = self.parent_transcription_pipe.recv()
1480
+ if status == 'success':
1481
+ segments, info = result
1482
+ self.detected_realtime_language = info.language if info.language_probability > 0 else None
1483
+ self.detected_realtime_language_probability = info.language_probability
1484
+ realtime_text = segments
1485
+ else:
1486
+ logging.error(f"Realtime transcription error: {result}")
1487
+ continue
1488
+ else:
1489
+ logging.warning("Realtime transcription timed out")
1490
+ continue
1491
+ except Exception as e:
1492
+ logging.error(f"Error in realtime transcription: {str(e)}")
1493
+ continue
1494
+ else:
1495
+ # Perform transcription and assemble the text
1496
+ segments, info = self.realtime_model_type.transcribe(
1497
+ audio_array,
1498
+ language=self.language if self.language else None,
1499
+ beam_size=self.beam_size_realtime,
1500
+ initial_prompt=self.initial_prompt,
1501
+ suppress_tokens=self.suppress_tokens,
1502
+ )
1463
1503
 
1464
- self.detected_realtime_language = info.language if info.language_probability > 0 else None
1465
- self.detected_realtime_language_probability = info.language_probability
1504
+ self.detected_realtime_language = info.language if info.language_probability > 0 else None
1505
+ self.detected_realtime_language_probability = info.language_probability
1506
+ realtime_text = " ".join(
1507
+ seg.text for seg in segments
1508
+ )
1466
1509
 
1467
1510
  # double check recording state
1468
1511
  # because it could have changed mid-transcription
@@ -1470,9 +1513,7 @@ class AudioToTextRecorder:
1470
1513
  self.recording_start_time > 0.5:
1471
1514
 
1472
1515
  logging.debug('Starting realtime transcription')
1473
- self.realtime_transcription_text = " ".join(
1474
- seg.text for seg in segments
1475
- )
1516
+ self.realtime_transcription_text = realtime_text
1476
1517
  self.realtime_transcription_text = \
1477
1518
  self.realtime_transcription_text.strip()
1478
1519
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RealtimeSTT
3
- Version: 0.2.3
3
+ Version: 0.2.4
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
@@ -341,6 +341,8 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
341
341
 
342
342
  - **enable_realtime_transcription** (bool, default=False): Enables or disables real-time transcription of audio. When set to True, the audio will be transcribed continuously as it is being recorded.
343
343
 
344
+ - **use_main_model_for_realtime** (bool, default=False): If set to True, the main transcription model will be used for both regular and real-time transcription. If False, a separate model specified by `realtime_model_type` will be used for real-time transcription. Using a single model can save memory and potentially improve performance, but may not be optimized for real-time processing. Using separate models allows for a smaller, faster model for real-time transcription while keeping a more accurate model for final transcription.
345
+
344
346
  - **realtime_model_type** (str, default="tiny"): Specifies the size or path of the machine learning model to be used for real-time transcription.
345
347
  - Valid options: 'tiny', 'tiny.en', 'base', 'base.en', 'small', 'small.en', 'medium', 'medium.en', 'large-v1', 'large-v2'.
346
348
 
@@ -9,7 +9,7 @@ with open('requirements.txt') as f:
9
9
 
10
10
  setuptools.setup(
11
11
  name="RealtimeSTT",
12
- version="0.2.3",
12
+ version="0.2.4",
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
File without changes