Skip to main content

A simple Python voice library for Voice Assistant

Project description

🎙️ pyvoicelib

PyPI Version Downloads Python Version License GitHub Stars


A simple, cross-platform Python voice assistant library for beginners, hobbyists, and developers.
Easily add speech recognition 🗣️ and text-to-speech 🔊 to your Python projects.


✨ Features

✅ Text-to-speech conversion (TTS)
✅ Speech recognition (STT)
✅ Simple API – both functions and VoiceAssistant class
✅ Set voice rate, volume, and gender (male/female/neutral)
✅ Cross-platform: Windows, macOS, Linux
✅ Python 3.6+ supported


📦 Installation

pip install pyvoicelib

For development (with testing):

git clone https://github.com/Yazirofi/pyvoicelib.git
cd pyvoicelib
pip install -r requirements-dev.txt

🚀 Quick Start

1. Standalone Functions

from pyvoicelib import speak, listen

# Text-to-speech
speak("Hello, I am your Python voice assistant!")

# Speech recognition
try:
    text = listen()
    print("You said:", text)
except Exception as e:
    print("Error:", e)

2. Using the VoiceAssistant Class

from pyvoicelib import VoiceAssistant

# Initialize assistant
assistant = VoiceAssistant(voice_rate=160, voice_volume=0.8, voice_gender="female")

# Speak
assistant.speak("Hi there, how can I help you?")

# Listen
try:
    command = assistant.listen()
    print("You said:", command)
except Exception as e:
    print("Error:", e)

🎛️ Voice Customization

assistant.set_voice_rate(180)   # Words per minute
assistant.set_voice_volume(0.7) # Volume (0.0 – 1.0)
assistant.set_voice_gender("male") # 'male', 'female', 'neutral'

Check available voices on your system:

print(assistant.get_available_voices())

🧪 Running Tests

We use pytest for testing.

pytest -v

All tests are located in the tests/ directory.


🛠️ Troubleshooting

No 'male' voice found. Using default system voice.

  • Your system may not provide explicitly labeled voices.
  • Try assistant.get_available_voices() to list supported voices.

speech_recognition or pyaudio ImportError

  • Install missing dependencies:

    pip install SpeechRecognition pyttsx3 pyaudio
    

❌ Microphone not working

  • Ensure your microphone is enabled and selected as the input device.

  • On Linux, install portaudio:

    sudo apt-get install portaudio19-dev
    

❌ Python version error

  • pyvoicelib requires Python 3.6+.

  • Check with:

    python --version
    

💡 Example Project – Simple Conversation Bot

from pyvoicelib import VoiceAssistant

assistant = VoiceAssistant(voice_gender="female")

while True:
    try:
        command = assistant.listen()
        if command:
            print("You:", command)
            if "exit" in command.lower():
                assistant.speak("Goodbye!")
                break
            else:
                assistant.speak(f"You said: {command}")
    except Exception as e:
        print("Error:", e)

🤝 Contributing

Pull requests are welcome! 🎉 Please run tests before submitting:

pytest -v

📖 Resources


📜 License

MIT License © 2025 Yazirofi


👉 This README is clean, stylish, and beginner-friendly. It has:

  • ✨ Emojis for readability
  • 🚀 Quick start & examples
  • 🛠️ Troubleshooting section
  • 💡 Example project

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvoicelib-0.1.2.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvoicelib-0.1.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file pyvoicelib-0.1.2.tar.gz.

File metadata

  • Download URL: pyvoicelib-0.1.2.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pyvoicelib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d0cd0ba8a5e2b5a1355f3af7ad07c33ff363ca7cce45ad1d5e5ec40c541d0f19
MD5 87cf950e0709cfaeb7702ef9e2cf2962
BLAKE2b-256 96dfdca775ef3bd76b73ebcbc535a2f952e8e790e1a3137d6d3f123addb89223

See more details on using hashes here.

File details

Details for the file pyvoicelib-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyvoicelib-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pyvoicelib-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8cdaf79968fc1fbc25e23d15fc4561aecf7f0a22c43c9ca25dc61066158470f6
MD5 001b20220d7fd51c15b1ecbebd92da7a
BLAKE2b-256 5a94aeeb8e5400f70d3d519875534c3e6fc7e11ce06c7a6687a782d0a9ca9c44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page