Skip to main content

A simple Python voice library for Voice Assistant

Project description

🎙️ pyvoicelib

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

Would you like me to also add badges (PyPI, Build, License, Python versions) at the top for extra style?

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.1.tar.gz (8.8 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.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyvoicelib-0.1.1.tar.gz
  • Upload date:
  • Size: 8.8 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.1.tar.gz
Algorithm Hash digest
SHA256 21943ecdbd9b0fc4ad1ff5ce445bec7b35b328438a41499372f408ee3daad612
MD5 37493c473ae4b78bbfad4d02dafa1d7f
BLAKE2b-256 366c0985c3b108e0bf09637b49739137603cc12b91cc51b53cb813fb8729a497

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyvoicelib-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed31d68acd5ba86afd201ab01e339b9e1a5ac211be50b86b7fb2c8c14efeeaf3
MD5 6636d550ddedc41523d98b84657a5537
BLAKE2b-256 f128ea3e3260b88e75e05a51edad98950480dd573a75f6b1d27ab531b8bd3a82

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