Skip to main content

A simple speech to command converter

Project description

A python library that converts speak to python commands. important: The library is still in development and may not work as expected.

Installation

pip install stc-converter==0.1

Usage

from stc import STC

stc = STC(start_command="computer", lang="en-US")

stc.add_command(function=print, commands=["print", "write",])

stc.run()

Now, when you say “computer, write hello world”, the program will print “hello world”

Limitations

  • The library is not perfect, so it may not work as expected

  • The library will only work with one command at a time

Dependencies

  • SpeechRecognition

  • PyAudio

  • Nltk

How to use

Start Command

The start command is the word that the program will listen to start the command. For example, if you set the start command to “computer”, the program will only listen to commands after you say “computer”. You must say the start command before every command. #### Example

from stc import STC

stc = STC(start_command="computer", lang="en-US")

stc.add_command(function=print, commands=["print", "write",])

stc.run()

Now, when you say “computer, write hello world”, the program will print “hello world”. But if you say “write hello world”, the program will not do anything. Importante:: The start command must be one word.

Language

The language is the language that the program will listen to. At the moment, the library only supports English and Portuguese and the default language is English. The language must be set to “en-US” for English and “pt-BR” for Portuguese.

Example

from stc import STC

stc = STC(start_command="computer", lang="en-US")

stc.add_command(function=print, commands=["print", "write",])

stc.run()

Add Command

The add command method is used to add a command to the program. The function parameter is the function that will be called when the command is said. The commands parameter is a list of words that the program will listen to call the function. The program will not only listen to the exact words in the list, but also to similar words. For example, if you add the command “print” and say “printer”, the program will call the function. To define the similarity of the words, the library uses the Levenshtein distance algorithm.

Example

from stc import STC

def open_file(file_name):
    with open(file_name, "r") as file:
        print(file.read())

stc = STC(start_command="computer", lang="en-US")

stc.add_command(function=open_file, commands=["open", "read", "show", "print"])

stc.run()

Context Definition

As long as you add functions to the program, maybe you need to add functions with the same name but with different contexts. For example, you may want to add a function to print a text and another function to print a number. To do that, you can use the context parameter. The context parameter is a string that will be used to define the context of the command. The context parameter is optional and the default value is ““.

When setting the STC object, you can set the context keyword that will be used to define the context of the command. The context keyword is optional and the default value is “using context”. That way, when you say the start command, the program will listen to the context keyword to define the context of the command. #### Example

from stc import STC

def open_file(file_name):
    with open(file_name, "r") as file:
        print(file.read())

def printer(text):
    print(text)

stc = STC(start_command="computer", lang="en-US", context_definer="using")

stc.add_command(function=open_file, commands=["open", "read", "show"], context="file")
stc.add_command(function=printer, commands=["print"], context="printer")

stc.run()

Now, when you say “computer, using file open, requirements.txt”, the program will call the function. But if you say “computer, using file print, requirements.txt”, the program will not do anything. Importante:: The context keyword must be one word and must be followed by the context of the command.

Importante:: Note that the only thing that will be passed to the function is the text after the context keyword. That way, the function will only receive the text “requirements.txt” and not the context keyword nor the start command. Your own function must be able to handle the text argument and exceptions.

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

stc_converter-0.0.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

stc_converter-0.0.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file stc_converter-0.0.1.tar.gz.

File metadata

  • Download URL: stc_converter-0.0.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.13

File hashes

Hashes for stc_converter-0.0.1.tar.gz
Algorithm Hash digest
SHA256 96a62c71039ba8bdbc1b19d11e10c9f9c0d8ffea2b4e2a8cd892dd085650096d
MD5 94fbbd10904fcffebd6351c564410207
BLAKE2b-256 c78f13705f8b7622752e901eda398504822f04d336e2e21ebccbfc89345504f9

See more details on using hashes here.

File details

Details for the file stc_converter-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for stc_converter-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e9816f5e2bd162818dbae1bcea06862b5fa9b1ecc56d9b376f8aaa1567c0871c
MD5 d6fef0216957ea1e9de9c023ce779e8e
BLAKE2b-256 0958c050166eb7419714f0a9132251294e1579b45307b58cb357c26c1e092edc

See more details on using hashes here.

Supported by

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