Voice Recognition with Python

When I saw Tony Stark (Iron Man) in Marvel movies, I always wanted a virtual assistant like Jarvis. Siri, Cortana, and Alexa still don’t have the same level of interaction. Searching the Internet, I found the project https://kripytonianojarvis.com/site/ which I found very interesting.

But I don’t think that’s what I want yet, so I decided to (try) create a virtual assistant. I know it won’t be easy, and this project will be something of a hobby.

The first part is voice communication with the computer, so I need the machine to understand my speech. In this post, I’m going to show code in python to capture speech from the microphone and transform it into text, recording it in a file.

Let’s go to code.

Installation of Libraries

pip install SpeechRecognition
pip install pyaudio

If you are on Windows you will need to use:

pip install pipwin 
pipwin install pyaudio

Although the code doesn’t explicitly call Pyaudio, we must access the microphone. Therefore, we must install it correctly.

Full Code

import speech_recognition as sr


def WriteMessage(message):
    try:
        with open("audio_transcription.txt", "a") as file:
            file.write(str(message) + "\n")
            file.close()
    except:
        print("Error on write " + message)


r = sr.Recognizer()
message = ""

while (message != "turn off"):
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source)
        print("Say something:")
        audio = r.listen(source)
        print("Hello")

    try:
        message = r.recognize_google(audio)
        print("You spoke: " + message)
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand message!")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition servic; {0}".format(e))

    WriteMessage(message)

Write Message

import speech_recognition as sr


def WriteMessage(message):
    try:
        with open("audio_transcription.txt", "a") as file:
            file.write(str(message) + "\n")
            file.close()
    except:
        print("Error on write " + message)

This first part of the code has the library import and the transcribed text function. It will be essential to send the text message with commands to the computer and other equipment. Have you thought about turning on the coffeemaker with a voice command? Great!

Voice Recognition

r = sr.Recognizer()
message = ""

while (message != "turn off"):
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source)
        print("Say something:")
        audio = r.listen(source)
        print("Hello")

    try:
        message = r.recognize_google(audio)
        print("You spoke: " + message)
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand message!")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition servic; {0}".format(e))

Google Speech Recognition performs voice recognition. There are two error handles. The first error refers to the fact that the machine does not understand the message. The second is related to the connection to the Google network. For everything to work correctly, you need an Internet connection.

Google Speech Recognition is a neural network for speech recognition. It is pretty robust as it will most of the time recognize speech without a voice timbre calibration step.

Interesting to note that the program works until you receive, by voice, the command “Turn off.”

Conclusion
We wrote a simple code that captures what was said and displays it in text format on the screen. In addition, everything that we told the machine records in a text file, and the program is closed when we say “Turn off.”

For future work, we will add commands for the computer to perform tasks through voice commands.

Requirement Analysis

Pressman [1] informs us that the execution of seven distinct functions performs the requirements engineering process: conception, survey, elaboration, negotiation, specification, validation, and management. The requirements modeling action results in one or more of the following types of models:

  • Requirements scenarios are represented from the point of view of various “actors” in the system.
  • Data models that represent the information domain for the problem.
  • Class-oriented: representing object-oriented classes (attributes and operations) and how classes collaborate to meet system requirements.
  • Flow-oriented models represent the functional elements of the system and how they transform data as it travels through the system.
  • Behavioral models that represent how software behaves as a result of external “events.”

Software requirements can be classified as follows [2]:

  • Functional Requirements: these are statements of services that the system must provide, how the system must react to specific inputs, and how the system must behave in certain situations. In some cases, functional requirements may also spell out what the system should not do.
  • Non-Functional Requirements: are restrictions on the services or functions offered by the system. They include timing constraints, constraints on the development process, and constraints imposed by standards. Unlike the individual features or services of the system, non-functional requirements often apply to the entire system.

Non-functional requirements can come from the characteristics required for the software (product requirements), from the organization that develops the software (organizational requirements), or from external sources [2].

 

QFD (Quality Function Deployment) is a quality management technique that translates customer needs into technical software requirements. QFD “focuses on maximizing customer satisfaction through the software engineering process” [1]. QFD identifies three types of requirements: Normal Requirements, Expected Requirements, Fascinating Requirements.

References:

[1] Pressman, Roger. Software Engineering 6ª edition (2006).
[2] Sommerville, Ian. Software Engineering 9ª edition (2012).

Discipline in Study

Many students try to study the entire content of the tests after launching the notice. This strategy is doomed to failure due to lack of time. Studies must start before the public announcement To explore the full range. This statement may seem illogical, as we may end up studying for a long time until the actual test, or worse, we may launch the test with subjects different from the ones we are looking for. That’s the price to pay.

The top quality of the contestant is the discipline of always studying. This regularity creates the approved and not fancy methods that “unveil the secret of the contests.” There are no secrets and no easy paths. The best analogy I’ve seen for this was Professor Granjeiro comparing studying competitions with a marathon. Only those in constant training can run a marathon. Even elite athletes who are without training cannot recover in a short period.

For those looking for magic formulas, I inform you that the process is simple: separate the material, study every day, stay focused, take exams for competitions. By following these steps, approval is guaranteed. So why do many give up? The point is, studying always is hard. So, are you willing to pay the price?

Artificial Intelligence to improve customer relations

I just read the news about the applications of the company Nuveto, a provider of cloud contact center solutions with AI technologies. They use Machine Learning to discover patterns of behavior and factors that result in company interest points in customer-company interactions.

I found the application of their chatbots interesting that can help even when the ChatBot does not retain the customer, and he needs to talk to an attendant. An example is applications capable of listening in real-time to what is being said (or written in a chat session). Based on all the experience gained through previous interactions with other customers, send alerts to the operator indicating suggestions for approach, language changes, discount offers, and others. “This AI-based virtual coach is an essential and primordial tool, as the results of the interactions will serve as training for you to be increasingly assertive in your suggestions,” says Leite.

The original news can be seen at https://inforchannel.com.br/inteligencia-artificial-ajuda-a-fortalecer-relacao-com-os-clientes/.