Code Monkey home page Code Monkey logo

offline-voice-control-on-raspberry-pi's Introduction

Offline Voice Control on Raspberry Pi.

Designed To Run On:

The Voice Control Consists of:

  • Speech-to-Text engine is a piece of software that interprets human voice into a string of text. It lets the computer know what is being said.
  • Text-to-Speech engine converts text into sound. It allows the computer to speak, probably as a response to your command.

The Voice Control uses:

  • Vosk as the Speech-to-Text engine.
  • PYTTSX3 as the Text-to-Speech engine.

Why Vosk ?

  • Supports 20+ languages and dialects - English, Indian English, German, French, Spanish, Portuguese, Chinese, Russian, Turkish, Vietnamese, Italian, Dutch, Catalan, Arabic, Greek, Farsi, Filipino, Ukrainian, Kazakh, Swedish, Japanese, Esperanto, Hindi, Czech, Polish. More to come.
  • Works offline, even on lightweight devices - Raspberry Pi, Android, iOS.
  • Installs with simple pip3 install vosk.
  • Portable per-language models are only 50Mb each, but there are much bigger server models available.
  • Provides streaming API for the best user experience (unlike popular speech-recognition python packages).
  • There are bindings for different programming languages, too - java/csharp/javascript etc.
  • Allows quick reconfiguration of vocabulary for best accuracy.
  • Supports speaker identification beside simple speech recognition.

to use the Voice Control System you will need to:

  • Speakers Plugged into the Raspberry Pi usingn Jack.
  • Microphone Plugged ( Wired USB or Bluetooth ).

Let's Get Started.

  • First you need to install the necessary library packages which are:

    • pip install pyaudio.
    • pip install vosk.
    • pip install pyttsx3.
  • or by using pip install -r requirments.txt

  • After checking that the Speaker and Microphone works properly start using the Voice Control System using the Engine implementation.

Speech To Text Engine:

Start using by importing Voice() which has seconds parameters that you can specity, default is 10 in your main application.

Code Implementation:
def voice(seconds = 10):
   start_time = time.time()
  
   stream.start_stream()
   print("Model Started ....")
   
   while True:

       current_time = time.time()
       elapsed_time = current_time - start_time
       
       data = stream.read(4000,exception_on_overflow = False)
       recogniser.AcceptWaveform(data)

       result = recogniser.Result()[14:-3]
       print(result)

       if elapsed_time > seconds:
           break

voice()

Text To Speech Engine:

Start using by importing speak() in your main application.

Code Implementation:
def speak(audio):
   engine = pyttsx3.init()
   engine.setProperty('rate', 150)
   print("Assistant : " + audio)
   engine.say(audio)
   engine.runAndWait()

Note: If you use the code in another python script you need to import these libraries.

import pyttsx3
from vosk import Model, KaldiRecognizer
import pyaudio
import os
import time

It's that simple!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.