|
@@ -28,6 +28,43 @@ See [release history](https://github.com/KoljaB/RealtimeSTT/releases).
|
|
|
|
|
|
> **Hint:** *Since we use the `multiprocessing` module now, ensure to include the `if __name__ == '__main__':` protection in your code to prevent unexpected behavior, especially on platforms like Windows. For a detailed explanation on why this is important, visit the [official Python documentation on `multiprocessing`](https://docs.python.org/3/library/multiprocessing.html#multiprocessing-programming).*
|
|
|
|
|
|
+## Quick Examples
|
|
|
+
|
|
|
+### Print everything being said:
|
|
|
+
|
|
|
+```python
|
|
|
+from RealtimeSTT import AudioToTextRecorder
|
|
|
+import pyautogui
|
|
|
+
|
|
|
+def process_text(text):
|
|
|
+ print(text)
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ print("Wait until it says 'speak now'")
|
|
|
+ recorder = AudioToTextRecorder()
|
|
|
+
|
|
|
+ while True:
|
|
|
+ recorder.text(process_text)
|
|
|
+```
|
|
|
+
|
|
|
+### Type everything being said:
|
|
|
+
|
|
|
+```python
|
|
|
+from RealtimeSTT import AudioToTextRecorder
|
|
|
+import pyautogui
|
|
|
+
|
|
|
+def process_text(text):
|
|
|
+ pyautogui.typewrite(text + " ")
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ print("Wait until it says 'speak now'")
|
|
|
+ recorder = AudioToTextRecorder()
|
|
|
+
|
|
|
+ while True:
|
|
|
+ recorder.text(process_text)
|
|
|
+```
|
|
|
+*Will type everything being said into your selected text box*
|
|
|
+
|
|
|
### Features
|
|
|
|
|
|
- **Voice Activity Detection**: Automatically detects when you start and stop speaking.
|
|
@@ -158,6 +195,19 @@ recorder.stop()
|
|
|
print(recorder.text())
|
|
|
```
|
|
|
|
|
|
+#### Standalone Example:
|
|
|
+
|
|
|
+```python
|
|
|
+from RealtimeSTT import AudioToTextRecorder
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ recorder = AudioToTextRecorder()
|
|
|
+ recorder.start()
|
|
|
+ input("Press Enter to stop recording...")
|
|
|
+ recorder.stop()
|
|
|
+ print("Transcription: ", recorder.text())
|
|
|
+```
|
|
|
+
|
|
|
### Automatic Recording
|
|
|
|
|
|
Recording based on voice activity detection.
|
|
@@ -167,8 +217,19 @@ with AudioToTextRecorder() as recorder:
|
|
|
print(recorder.text())
|
|
|
```
|
|
|
|
|
|
+#### Standalone Example:
|
|
|
+
|
|
|
+```python
|
|
|
+from RealtimeSTT import AudioToTextRecorder
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ with AudioToTextRecorder() as recorder:
|
|
|
+ print("Transcription: ", recorder.text())
|
|
|
+```
|
|
|
+
|
|
|
When running recorder.text in a loop it is recommended to use a callback, allowing the transcription to be run asynchronously:
|
|
|
|
|
|
+
|
|
|
```python
|
|
|
def process_text(text):
|
|
|
print (text)
|
|
@@ -177,6 +238,21 @@ while True:
|
|
|
recorder.text(process_text)
|
|
|
```
|
|
|
|
|
|
+#### Standalone Example:
|
|
|
+
|
|
|
+```python
|
|
|
+from RealtimeSTT import AudioToTextRecorder
|
|
|
+
|
|
|
+def process_text(text):
|
|
|
+ print(text)
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ recorder = AudioToTextRecorder()
|
|
|
+
|
|
|
+ while True:
|
|
|
+ recorder.text(process_text)
|
|
|
+```
|
|
|
+
|
|
|
### Wakewords
|
|
|
|
|
|
Keyword activation before detecting voice. Write the comma-separated list of your desired activation keywords into the wake_words parameter. You can choose wake words from these list: alexa, americano, blueberry, bumblebee, computer, grapefruits, grasshopper, hey google, hey siri, jarvis, ok google, picovoice, porcupine, terminator.
|
|
@@ -188,6 +264,18 @@ print('Say "Jarvis" then speak.')
|
|
|
print(recorder.text())
|
|
|
```
|
|
|
|
|
|
+#### Standalone Example:
|
|
|
+
|
|
|
+```python
|
|
|
+from RealtimeSTT import AudioToTextRecorder
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ recorder = AudioToTextRecorder(wake_words="jarvis")
|
|
|
+
|
|
|
+ print('Say "Jarvis" to start recording.')
|
|
|
+ print(recorder.text())
|
|
|
+```
|
|
|
+
|
|
|
### Callbacks
|
|
|
|
|
|
You can set callback functions to be executed on different events (see [Configuration](#configuration)) :
|
|
@@ -203,6 +291,22 @@ recorder = AudioToTextRecorder(on_recording_start=my_start_callback,
|
|
|
on_recording_stop=my_stop_callback)
|
|
|
```
|
|
|
|
|
|
+#### Standalone Example:
|
|
|
+
|
|
|
+```python
|
|
|
+from RealtimeSTT import AudioToTextRecorder
|
|
|
+
|
|
|
+def start_callback():
|
|
|
+ print("Recording started!")
|
|
|
+
|
|
|
+def stop_callback():
|
|
|
+ print("Recording stopped!")
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ recorder = AudioToTextRecorder(on_recording_start=start_callback,
|
|
|
+ on_recording_stop=stop_callback)
|
|
|
+```
|
|
|
+
|
|
|
### Feed chunks
|
|
|
|
|
|
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:
|
|
@@ -211,6 +315,20 @@ If you don't want to use the local microphone set use_microphone parameter to fa
|
|
|
recorder.feed_audio(audio_chunk)
|
|
|
```
|
|
|
|
|
|
+#### Standalone Example:
|
|
|
+
|
|
|
+```python
|
|
|
+from RealtimeSTT import AudioToTextRecorder
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ recorder = AudioToTextRecorder(use_microphone=False)
|
|
|
+ with open("audio_chunk.pcm", "rb") as f:
|
|
|
+ audio_chunk = f.read()
|
|
|
+
|
|
|
+ recorder.feed_audio(audio_chunk)
|
|
|
+ print("Transcription: ", recorder.text())
|
|
|
+```
|
|
|
+
|
|
|
### Shutdown
|
|
|
|
|
|
You can shutdown the recorder safely by using the context manager protocol:
|
|
@@ -220,12 +338,25 @@ with AudioToTextRecorder() as recorder:
|
|
|
[...]
|
|
|
```
|
|
|
|
|
|
+
|
|
|
Or you can call the shutdown method manually (if using "with" is not feasible):
|
|
|
|
|
|
```python
|
|
|
recorder.shutdown()
|
|
|
```
|
|
|
|
|
|
+#### Standalone Example:
|
|
|
+
|
|
|
+```python
|
|
|
+from RealtimeSTT import AudioToTextRecorder
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ with AudioToTextRecorder() as recorder:
|
|
|
+ [...]
|
|
|
+ # or manually shutdown if "with" is not used
|
|
|
+ recorder.shutdown()
|
|
|
+```
|
|
|
+
|
|
|
## Testing the Library
|
|
|
|
|
|
The test subdirectory contains a set of scripts to help you evaluate and understand the capabilities of the RealtimeTTS library.
|
|
@@ -420,7 +551,7 @@ Shoutout to [Steven Linn](https://github.com/stevenlafl) for providing docker su
|
|
|
|
|
|
## License
|
|
|
|
|
|
-MIT
|
|
|
+[MIT](https://github.com/KoljaB/RealtimeSTT?tab=MIT-1-ov-file)
|
|
|
|
|
|
## Author
|
|
|
|