Offline Multilingual Voice Bot Library for Python
Project description
Voice of Python
Offline Multilingual Voice Bot Library for Python 🎙️
voice_of_python is a robust Python library providing offline multilingual speech recognition and text-to-speech (TTS) capabilities. Powered by the Vosk toolkit for precise offline speech-to-text and pyttsx3 for offline TTS, it seamlessly supports multiple languages with automatic language detection.
🌟 Key Features
- Offline Processing: Complete offline speech-to-text using Vosk models—no APIs or internet required.
- Audio Inputs: Record audio directly from the microphone or process existing WAV files.
- Auto-Language Detection: Smartly identifies spoken languages using
langid. - Text-to-Speech (TTS): Synthesizes responses in the detected language's voice (if locally available).
- CPU Optimized: Fully functional on CPU, making it perfect for local, privacy-centric applications.
- LLM Ready: Purpose-built for easy integration with large language models (LLMs) and custom chatbots.
📦 Installation
Ensure you have installed the required dependencies. You can install the package directly from PyPI:
pip install voice_of_python
(Alternatively, to install dependencies manually: pip install vosk langid pyttsx3 sounddevice numpy soundfile)
Note: Download and extract Vosk models for your supported languages separately to a local folder.
🚀 Quick Start
1. Initialize the Voice Bot
Provide the paths to your downloaded Vosk models:
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 & Transcribe Live Audio
Listen from the microphone, detect language, and transcribe text:
text, lang_code = bot.record_and_transcribe(record_duration=5)
print(f"Detected language: {lang_code}")
print(f"Recognized text: {text}")
3. Integrate with an LLM (Example)
Pass the transcribed text to your backend model (like OpenAI, LLaMA, etc.) to generate a conversational response.
# Example response from an LLM
reply_text = "यहाँ आपका उत्तर है"
4. Speak the Reply
Respond to the user naturally in the detected language:
bot.speak_text(reply_text, lang_code)
5. Process Existing Audio Files
Alternatively, handle pre-recorded audio files:
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)
Initializes the bot.
model_paths: A dictionary mapping language codes to their respective local Vosk model paths (e.g.,{"en": "/path"}).sample_rate: Sampling rate for audio processing (default is 16000 Hz).
record_and_transcribe(record_duration: int = 5) -> tuple[str, str]
Records audio directly from the default microphone.
- Returns: A tuple containing
(recognized_text, language_code).
process_audio_and_reply(audio_input: Union[str, np.ndarray], reply_text: str)
Transcribes provided audio, detects language, and immediately speaks the provided reply.
audio_input: A file path to a WAV file or a raw numpy array.reply_text: The text response to be spoken aloud.
speak_text(text: str, lang_code: str)
Reads out the text using the system's text-to-speech engine.
text: Text to synthesize.lang_code: The language code to select the proper voice.
🤝 Contributing
We welcome contributions! Please feel free to open issues, submit pull requests, or discuss new features on GitHub.
📚 Acknowledgements
This project builds upon several amazing open-source libraries:
- Vosk: For robust offline speech recognition.
- pyttsx3: For text-to-speech conversion.
- langid: For accurate language identification.
💬 Support
If you encounter any bugs or have questions, please open an issue on GitHub.
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.1.tar.gz.
File metadata
- Download URL: voice_of_python-0.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
546badb1cecab1b66857d6f52a5f64aa10311ccace289f10741cd243b4a224d7
|
|
| MD5 |
c701a68f5b4e20ee42a76b5f9b9165cd
|
|
| BLAKE2b-256 |
522b6fb799d912609bfa3d0faea1623b1d2c5b2a24a237983ee6febe9bbf6741
|
File details
Details for the file voice_of_python-0.1.1-py3-none-any.whl.
File metadata
- Download URL: voice_of_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80cf16b061618c4443baf19323c9dd60201462d27b8bf8be56e556029155f535
|
|
| MD5 |
04c800c970c7ad0b1d850ff3330720d4
|
|
| BLAKE2b-256 |
5c4b8f4e368fb46ec9335b62913574d49a1fed8fd686a5d28d94a0927b1cccc4
|