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.3.tar.gz (9.1 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.3-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyvoicelib-0.1.3.tar.gz
  • Upload date:
  • Size: 9.1 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.3.tar.gz
Algorithm Hash digest
SHA256 e3779543f4be9cdde2a6af1878e1a4d408cea64d4d6f2c6c19aee56f27adbd1f
MD5 a2e4b2ef1ee471f62a09d12ce097379c
BLAKE2b-256 a9fcb3a546be2896a33f9042aa721edabfb910ba57e4022f1289d8bc9c01cf2a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyvoicelib-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 55bdead980b6de7c8dbb7db53b5838b1c869ce4191adae1c917f86faba29d259
MD5 90d25d2e04262f7e0cf273a02698bdf3
BLAKE2b-256 d63ca097a1fb3870cff7e765470423d64b3a9b391253a3df27837760d02a3d7c

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