Offline multilingual voice bot with Vosk ASR and pyttsx3 TTS
Project description
voice_of_python
Offline Multilingual Voice Bot Library for Python
voice_of_python is a Python library that provides offline multilingual speech recognition and text-to-speech (TTS) capabilities. It uses the Vosk toolkit for offline speech-to-text and pyttsx3 for offline TTS, supporting multiple languages through automatic language detection.
Features
- Record audio from microphone or accept existing WAV audio files.
- Offline speech-to-text using Vosk models (no API or internet required).
- Automatic language detection with
langid. - Text-to-speech in detected language voice (if available locally).
- Works fully on CPU; suitable for local and privacy-sensitive applications.
- Designed for easy integration with chatbots and LLMs.
Installation
Install dependencies:
pip install vosk langid pyttsx3 sounddevice numpy soundfile
Note: Download and provide local Vosk models for supported languages separately.
Usage
1. Initialize the library with Vosk model paths
from voice_of_python import MultiLingualVoiceBot
model_paths = {
"en": "/path/to/vosk-model-en-us-0.22",
"hi": "/path/to/vosk-model-small-hi-0.22"
}
bot = MultiLingualVoiceBot(model_paths)
2. Record from microphone and get transcription
text, lang_code = bot.record_and_transcribe(record_duration=5)
print(f"Detected language: {lang_code}")
print(f"Recognized text: {text}")
3. Integrate with your LLM or AI model
Pass text to your backend model to generate a reply message.
reply_text = "यहाँ आपका उत्तर है"
4. Speak reply in detected language
bot.speak_text(reply_text, lang_code)
5. Alternatively, process external audio file and speak reply
audio_file = "user.wav" reply_text = "Thank you for your question." bot.process_audio_and_reply(audio_file, reply_text)
API Reference
-
MultiLingualVoiceBot(model_paths: dict, sample_rate: int = 16000)
Initialize with{language_code: vosk_model_path}mapping. -
record_and_transcribe(record_duration: int = 5) -> (str, str)
Record from mic and return transcription and detected language code. -
process_audio_and_reply(audio_input: Union[str, np.ndarray], reply_text: str)
Transcribe audio (file path or raw numpy array), detect language, speak reply text. -
speak_text(text: str, lang_code: str)
Speak given text in specified language voice.
Contributing
Contributions welcome! Please open issues or pull requests on GitHub.
Acknowledgements
- Vosk: https://alphacephei.com/vosk/
- pyttsx3: https://pyttsx3.readthedocs.io/en/latest/
- langid: https://github.com/saffsd/langid.py
Support
Please report issues or questions on the GitHub repository.
Enjoy building multilingual, offline voice-enabled applications with voice_of_python!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file voice_of_python-0.1.0.tar.gz.
File metadata
- Download URL: voice_of_python-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04bfe2b1f70183fd80777dae4759c011bdb9281f47baaedb2ad8249b864146ef
|
|
| MD5 |
cfa1258fbc69cce34f4a1d8138dfa84e
|
|
| BLAKE2b-256 |
70be2a866b7967ddd0292e7db23b66db3812a6c0c6507fc43d1e827889e96d4d
|
File details
Details for the file voice_of_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: voice_of_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b744bdb99fb161d81cbe226ec70b9b5f4087eda47ef43352e320633ca4c56125
|
|
| MD5 |
fb2692d2857ed9217b1c242fdba86e23
|
|
| BLAKE2b-256 |
5deaee104446b8b48448fd1ede12f796409658b581d8488ed0dbfa76c03e2924
|