Speechrecognition 3.8.1

Содержание:

Requirements

API Key

Google Speech Recognition API requires an API key. This library defaults to using one that was reverse engineered out of Chrome, but it is not recommended that you use this API key for anything other than personal or testing purposes.

PyAudio (for microphone users)

On Debain-based distributions such as Ubuntu, you can generally install PyAudio by running sudo apt-get install python-pyaudio python3-pyaudio, which will install it for both Python 2 and Python 3.

On other POSIX-based systems, simply use the packages provided on the downloads page linked above, or compile and install it from source.

# Класс микрофона

Теперь вместо использования аудиофайла в качестве источника вы будете использовать системный микрофон по умолчанию. Вы можете получить к нему доступ, создав экземпляр класса Microphone.

123

Если в вашей системе нет микрофона по умолчанию, или вы хотите использовать микрофон, отличный от стандартного, вам нужно будет указать, какой из них использовать, указав индекс устройства. Вы можете получить список имен микрофонов, вызвав статический метод list_microphone_names() класса Microphone.

123456789101112

Обратите внимание, что ваш вывод может отличаться от приведенного выше примера. Индекс устройства микрофона — это индекс его имени в списке, возвращаемом функцией list_microphone_names()

Например, учитывая вышеприведенный вывод, если вы хотите использовать микрофон с именем «front», который имеет индекс 3 в списке, вы должны создать экземпляр микрофона, например:

Индекс устройства микрофона — это индекс его имени в списке, возвращаемом функцией list_microphone_names(). Например, учитывая вышеприведенный вывод, если вы хотите использовать микрофон с именем «front», который имеет индекс 3 в списке, вы должны создать экземпляр микрофона, например:

12

Тем не менее, для большинства проектов вы, вероятно, захотите использовать системный микрофон по умолчанию.

Использование listen() для ввода с микрофона

Теперь, когда у вас есть готовый экземпляр Microphone, пришло время захватить некоторые данные.

Как и класс AudioFile, Microphone является контекстным менеджером. Вы можете захватить ввод с микрофона, используя метод listen() класса Recognizer внутри блока with. Этот метод принимает источник звука в качестве первого аргумента и записывает ввод от источника до тех пор, пока не будет обнаружена тишина.

12

Как только вы выполните блок with, попробуйте сказать «привет» в свой микрофон. Подождите, пока приглашение переводчика не отобразится снова. Как только будете готовы распознать речь добавьте:

1

Если запрос не возвращается, ваш микрофон, скорее всего, воспринимает слишком много окружающего шума. Вы можете прервать процесс с помощью , чтобы вернуть ваше приглашение.

Чтобы обрабатывать окружающий шум, вам нужно использовать метод класса Recognizer, как вы это делали, когда пытались разобраться в шумном аудиофайле. Поскольку ввод с микрофона гораздо менее предсказуем, чем ввод из аудиофайла, рекомендуется делать это каждый раз, когда вы слушаете вход с микрофона.

123

После запуска приведенного выше кода, подождите секунду, пока метод сделает свое дело, затем попробуйте сказать «привет» в микрофон. Опять же, вам придется немного подождать, пока переводчик предложит вернуться, прежде чем попытаться распознать речь.

анализирует источник звука в течение одной секунды. Если это кажется вам слишком длинным, не стесняйтесь изменить его с помощью аргумента продолжительности ключевого слова.

Документация рекомендует использовать продолжительность не менее 0.5 секунд. В некоторых случаях вы можете обнаружить, что длительность, превышающая значение по умолчанию в одну секунду, приводит к лучшим результатам. Минимальное значение, которое вам нужно, зависит от окружающей среды микрофона. К сожалению, эта информация обычно неизвестна во время разработки. Длительность по умолчанию в одну секунду подходит для большинства приложений.

Обработка неузнаваемой речи

Попробуйте набрать предыдущий пример кода и сделать несколько неразборчивых шумов в микрофон. Вы должны получить что-то вроде этого в ответ:

12345

Аудио, которое не может быть сопоставлено с текстом API, вызывает исключение . Вы должны всегда заключать вызовы API в блоки и , чтобы обработать это исключение.

ПРИМЕЧАНИЕ

Возможно, вам придется приложить больше усилий, чем вы ожидаете, чтобы получить исключение. API работает очень усердно, чтобы транскрибировать любые звуки. Даже короткие ворчания были расшифрованы как слова «как» для меня. Кашель, хлопки в ладоши и щелчки языка постоянно поднимали бы исключение.

Developing

To hack on this library, first make sure you have all the requirements listed in the «Requirements» section.

  • Most of the library code lives in .
  • Examples live under the directory, and the demo script lives in .
  • The FLAC encoder binaries are in the directory.
  • Documentation can be found in the directory.
  • Third-party libraries, utilities, and reference material are in the directory.

To install/reinstall the library locally, run in the project root directory.

Before a release, the version number is bumped in and . Version tags are then created using .

Releases are done by running to build the Python source packages, sign them, and upload them to PyPI.

Testing

To run all the tests:

python -m unittest discover --verbose

Testing is also done automatically by TravisCI, upon every push. To set up the environment for offline/local Travis-like testing on a Debian-like system:

sudo docker run --volume "$(pwd):/speech_recognition" --interactive --tty quay.io/travisci/travis-python:latest /bin/bash
su - travis && cd /speech_recognition
sudo apt-get update && sudo apt-get install swig libpulse-dev
pip install --user pocketsphinx monotonic && pip install --user flake8 rstcheck && pip install --user -e .
python -m unittest discover --verbose # run unit tests
python -m flake8 --ignore=E501,E701 speech_recognition tests examples setup.py # ignore errors for long lines and multi-statement lines
python -m rstcheck README.rst reference/*.rst # ensure RST is well-formed

FLAC Executables

The built FLAC executables should be bit-for-bit reproducible. To rebuild them, run the following inside the project directory on a Debian-like system:

# download and extract the FLAC source code
cd third-party
sudo apt-get install --yes docker.io

# build FLAC inside the Manylinux i686 Docker image
tar xf flac-1.3.2.tar.xz
sudo docker run --tty --interactive --rm --volume "$(pwd):/root" quay.io/pypa/manylinux1_i686:latest bash
    cd /root/flac-1.3.2
    ./configure LDFLAGS=-static # compiler flags to make a static build
    make
exit
cp flac-1.3.2/src/flac/flac ../speech_recognition/flac-linux-x86 && sudo rm -rf flac-1.3.2/

# build FLAC inside the Manylinux x86_64 Docker image
tar xf flac-1.3.2.tar.xz
sudo docker run --tty --interactive --rm --volume "$(pwd):/root" quay.io/pypa/manylinux1_x86_64:latest bash
    cd /root/flac-1.3.2
    ./configure LDFLAGS=-static # compiler flags to make a static build
    make
exit
cp flac-1.3.2/src/flac/flac ../speech_recognition/flac-linux-x86_64 && sudo rm -r flac-1.3.2/

Quick Start

Train

  1. Connect your Voice Recognition V3 Module with Arduino, By Default:

  2. Download VoiceRecognitionV3 library.(download zip file or use command)

  3. When use zip format file, extract VoiceRecognitionV3.zip to folder, or if you use command copy VoiceRecognitionV3 to .

  4. Open vr_sample_train(File -> Examples -> VoiceRecognitionV3 -> vr_sample_train)

  5. Choose right Arduino board(Tool -> Board, UNO recommended), Choose right serial port.

  6. Click Upload button, wait until Arduino is uploaded.

  7. Open Serial Monitor. Set baud rate 115200, set send with Newline or Both NL & CR.

  8. Send command (case insensitive) to check Voice Recognition Module settings. Input , and hit to send.

  9. Train Voice Recognition Module. Send command to train record 0 with signature «On». When Serial Monitor prints «Speak now», you need speak your voice(can be any word, meaningful word recommended, may be ‘On’ here), and when Serial Monitor prints «Speak again», you need repeat your voice again. If these two voice are matched, Serial Monitor prints «Success», and «record 0» is trained, or if are not matched, repeat speaking until success.When training, the two led on the Voice Recognition Module can benefit your training process. After send command, the SYS_LED is blinking which remind you to be ready, then speak your voice as soon as the STATUS_LED lights on, the record finishes once when the STATUS_LED lights off. Then the SYS_LED is blinking again, these status repeated, when the training is successful, SYS_LED and STATUS_LED blink together, if training is failed SYS_LED and STATUS_LED blink together quickly.

  10. Train another record. Send command to train record 1 with signature «Off». Choose your favorite words to train (it can be any word, meaningful word recommended, may be ‘Off’ here).

  11. Send command to load voice. And say your word to see if the Voice Recognition Module can recognize your words.

    If the voice is recognized, you can see.

  12. Train finish. Train sample also support several other commands.

Control LED Sample

  1. Open vr_sample_control_led(File -> Examples -> VoiceRecognitionV3 -> vr_sample_control_led)
  2. Choose right Arduino board(Tool -> Board, UNO recommended), Choose right serial port.
  3. Click Upload button, wait until Arduino is uploaded.
  4. Open Serial Monitor. Set baud rate 115200.
  5. Say your trained voice to control the LED on Arduino UNO board. When record 0 is recognized, the led turns on. When record 1 is recognized, the led turns off.
  6. Control led finish.

Best Voice Recognition Software for Google Docs: Google Docs Voice Typing

Google Docs Voice Typing is a free tool found within the Google Docs word processor. Speak into your computer’s microphone, and the software will translate your words into text on the screen. You can also issue commands to navigate through your documents and edit them. Google Docs Voice Typing is good for Google Docs users who want a free, no-frills solution for hands-free dictation.

Google Docs Voice Typing Pricing

Google Docs Voice Typing comes free with Google Docs. All you need to do is open Google Docs with a desktop version of the Chrome web browser, and you can use your computer’s built-in microphone to dictate. This is similar to other voice recognition tools that are also free add-ons.

Google Docs Voice Typing Features

Google Docs Voice Typing allows you to dictate and edit your Google Docs files completely hands-free. The software works with any desktop version of Google Chrome and allows you to both dictate text and navigate around documents with voice commands. It also allows voice dictation in 62 different languages.

Google Docs Voice Typing Features include:

Dictation

As its name implies, Google Docs Voice Typing allows you to create documents without touching your keyboard. You can also edit your documents by saying things like “select paragraph” or “italics” to format your content the way that you want it. This is a powerful feature only surpassed by Dragon. Google Docs Voice Typing is good for users who want powerful voice dictation mixed with a capable word processing app.

Automation

Google Docs Voice Typing is not a smart assistant like Google Assistant is. As such, it cannot interact with other apps or give you traffic information. Unlike Dragon, you can only dictate Google Docs files. This software is best suited for users who are fine with using a voice assistant for automating their daily work lives.

Accuracy

Google Docs Voice Typing is very accurate. It even understood our dictation despite heavy background noise. It’s impressive for a free solution, but it’s still not as accurate as Dragon. That platform does a much better job at understanding natural speech and mispronunciations. Still, Google Docs Voice Typing is good for those who want hands-free dictation that understands natural speech.

Language Support

The software supports 62 languages, including Spanish, French, German, Japanese, and Korean. This far exceeds that of Dragon, which is an expensive product that only supports up to six languages. Google Docs Voice typing is ideal for multilingual users who want powerful dictation in many different languages.

What Google Docs Voice Typing Is Missing

Google Docs Voice Typing only works with the company’s own word processor. Additionally, it only allows you to type and edit text within that program. If you want to dictate words in many different programs as well as control your PC’s functionality, then you should check out Dragon. That service gives you full control over using your computer as well the ability to dictate in Microsoft Word.

Google Docs is popular with business users, and many appreciate the ability to dictate to the software and work hands-free. Users report that accuracy for dictation is generally good and typos are few. With that in mind, there are many complaints about the lack of a phone support line for Google Docs.

Conclusion

As you can see, it is pretty easy and simple to use this library for converting speech to text. This library is widely used out there in the wild, make sure you master it, check their official documentation.

If you want to convert text to speech in Python as well, check this tutorial.

Read Also: How to Recognize Optical Characters in Images in Python.

Happy Coding

View Full Code
Sharing is caring!

Read Also

How to Translate Text in Python

Learn how to do text translation using Google Translate API with Googletrans wrapper library to translate text into more than 100 languages using Python.

Visit →

How to Perform Text Classification in Python using Tensorflow 2 and Keras

Building deep learning models (using embedding and recurrent layers) for different text classification problems such as sentiment analysis or 20 news group classification using Tensorflow and Keras in Python

Visit →

How to Play and Record Audio in Python

Learn how to play and record sound files using different libraries such as playsound, Pydub and PyAudio in Python.

Visit →

Best Voice Recognition Software for Android Users: Google Assistant

Google Assistant is the company’s AI attendant that comes free with Android phones as well as a number of Chromebook tablets and smart speakers. There are a number of ways you can use the software’s capabilities to help you search the web, dictate notes, and control apps. It also has the most powerful speech recognition engine out of all the AI assistants. It is perfect for Android users who want AI-backed help with routine work tasks and reminders.

Google Assistant Pricing

Google Assistant comes bundled for free with any version of Android after 6.0 (Marshmallow). It’s also included on a number of smart devices such as speakers, televisions, car dashboards, and more. Just say “Hey Google” to use the software. This is very similar to how Siri works with Apple devices.

Google Assistant Features

Google Assistant allows you to dictate and use common features on your smartphone without using your hands, such as text messaging and using the software to translate your words into more than 150 languages. While there is an iOS app, its functionality is very limited compared to the version found on Android phones. For example, it cannot be used to open and close other applications on an Apple product, but this function is available on the Android version.

Google Assistant’s features include:

Dictation

Google Assistant allows you to dictate notes on your phone. Simply say “Hey Google, take a note.” The Assistant will ask you what the note is, and you can then dictate. You can then view your text on your phone’s Notes app. This works in the same manner as Siri and Cortana. However, it does not allow you to create and edit documents like you can with Dragon on the PC, making Google Assistant a better fit for mobile users who want to jot down notes on their phone.

Automation

Automating tasks is where Google Assistant excels. Google Assistant allows you to quickly and easily do things like set timers, get weather information, and send text messages. Many apps offer integration with Google Assistant, so you can hail an Uber ride or order lunch for the office via Seamless with your voice. This is more robust than other smart assistants. It’s great for users who don’t want to deal with opening apps and typing.

Accuracy

Google Assistant is fairly accurate and will understand you a majority of the time, even if you aren’t speaking clearly or use a lot of “uhms” and “ahs” in your commands. However, its accuracy is only slightly above other smart assistants available, and ambient noise can sometimes confuse the assistant.

Language Support

Google Assistant is currently available in Danish, Dutch, English, French, German, Hindi, Italian, Japanese, Korean, Norwegian, Spanish, and Swedish. Additionally, it can understand and translate more than 150 languages. This is some of the most powerful language support in voice recognition software to date. Google Assistant is good for users who often do business internationally.

What Google Assistant Is Missing

Google Assistant does not understand more advanced voice commands for editing notes. You cannot use the assistant to format text in services like Google Docs, either. There is also no way to use Google Assistant on a desktop outside of Chromebooks. And while there is an iOS version, it is not embedded into the OS, so you won’t be able to control other applications or change system settings.

Google Assistant is generally regarded as the best smartphone assistant to date. It is better at understanding speech and can integrate with more apps than Siri or Cortana, and the system works incredibly fast. However, users report that the system is hard to use when there is background noise.

Examples of where you might have used voice recognition

As voice recognition improves, it is being implemented in more places and its very likely you have already used it. Below are some examples of where you might encounter voice recognition.

  • Automated phone systems — Many companies today use phone systems that help direct the caller to the correct department. If you have ever been asked something like «Say or press number 2 for support» and you say «two,» you used voice recognition.
  • Google Voice — Google voice is a service that allows you to search and ask questions on your computer, tablet, and phone.
  • Digital assistant — Amazon Echo, Apple’s Siri, and Google Assistant use voice recognition to interact with digital assistants that helps answer questions.
  • Car Bluetooth — For cars with Bluetooth or Handsfree phone pairing, you can use voice recognition to make commands, such as «call my wife» to make calls without taking your eyes off the road.

Installing SpeechRecognition#

SpeechRecognition is compatible with Python 2.6, 2.7 and 3.3+, but requires some . For this tutorial, I’ll assume you are using Python 3.3+.

You can install SpeechRecognition from a terminal with pip:

Once installed, you should verify the installation by opening an interpreter session and typing:

>>>

Note: The version number you get might vary. Version 3.8.1 was the latest at the time of writing.

Go ahead and keep this session open. You’ll start to work with it in just a bit.

SpeechRecognition will work out of the box if all you need to do is work with existing audio files. Specific use cases, however, require a few dependencies. Notably, the PyAudio package is needed for capturing microphone input.

You’ll see which dependencies you need as you read further. For now, let’s dive in and explore the basics of the package.

Codec notes

There are other concerns that arise when trying to stream infinitely. In some
countries, data is expensive and sending uncompressed PCM formatted audio is
simply not practical. At 16kHz, streaming uncompressed 16-bit PCM data requires
256 kilobits per second of data, ignoring the comparatively small overhead of
header/auxiliary data. On low-bandwidth connections, this is too high of a data
rate to reliably use the cloud for recognition. It becomes necessary to use a
codec. Of the codecs supported by the speech APIs, we experimented with FLAC,
AMR-WB, and Opus (in an Ogg container). For the former two, we leverage the
Android framework’s encoder. FLAC is a lossless codec (unlike most audio codecs)
and will get you roughly a factor of 2 in data compression. It introduces a few
hundred milliseconds of latency, but is quite acceptable in most cases. AMR-WB offers
a much more appealing compression ratio, but in relatively noisy conditions
performs very badly for speech recognition. We do not recommend using AMR-WB for
speech recognition under any circumstances.

Finally, the Opus codec delivers quite impressive results for speech
recognition. Unfortunately, the Android framework does not ship with an Opus
encoder, so we included a native implementation in our library.
At rates at least as low as 24 kilobits per second (a compression
ratio of nearly 11), recognition quality does not seem to be impacted at all. We
know that with captions, accuracy is critical, so in Live Transcribe, we
configured our Opus codec to use a more conservative 32 kbps with variable
bitrate (VBR) enabled. This is sufficient for minimizing data streaming costs
(note that music streaming services use bitrates many times higher than this).
However, there is still a bit of latency associated with Opus compression. There
is one more fairly technical detail that we use to minimize latency in our Opus
stream. For every block of audio that is pushed into the Ogg/Opus stream, we
flush the Ogg stream rather than let the ogg library decide on its own when to
push out the next block of data. This causes a slight increase in bitrate, but
a significant reduction in latency. For the curious, deep in our encoder is a
«low_latency_mode» flag. As a user of this library nothing need be done to
enable that. Just request the following settings for your
CloudSpeechSessionParams:

Best Voice Recognition Software for Quick, Easy Note Taking: Speechnotes

Speechnotes is a browser-based dictation app that is available for free, with the option to unlock extra features and remove ads for $9.99. Speechnotes allows you to dictate and format text with your computer’s microphone. You can then export the text to a text file for further editing in a word processor. Speechnotes is good for staff who want to quickly put their thoughts into text and don’t need advanced voice editing features.

Speechnotes Pricing

Speechnotes is free to use with any browser. You can purchase Speechnotes Premium for $9.99 as a Chrome extension. Premium removes ads and adds a full-screen mode, dark mode, and a word count module. Still, most users will be fine with the free version.

Speechnotes Features

Speechnotes allows you to dictate speech through your web browser. You can export your text to a .doc or .txt file. You can also send the file directly to your Google Drive. It requires no setup to use, although it does not have nearly as many functions as other dictation software on the market.

Dictation

Open Speechnotes, and you can immediately start writing down your thoughts. The software offers commands for punctuation marks, new lines, parentheses, and more. The document will automatically save without you having to make an account. This makes getting started with Speechnotes a much quicker experience than other dictation apps. The software is good for users who want to quickly jot down their thoughts through dictation.

Automation

Speechnotes does not offer anything by way of automation features. Unlike Dragon, you cannot use Speechnotes to verbally control browser functions. You will have to log on to the website by typing in the URL, and you will have to use your mouse to save your progress. Therefore, Speechnotes is best suited for workers who do not need to control apps or pull up information.

Accuracy

Speechnotes is accurate, although it does have some issues. If you say “uh” while dictating, Speechnotes will interpret that as an “a” and it will show up on screen. This differs from Dragon, which uses a natural speech recognition engine to understand imperfect human speech and correct it during dictation.

Language Support

Speechnotes supports dictation in more than 50 different languages. It comes up short when compared with Google Docs Voice Typing’s 150+ supported languages. Still, the languages supported are among the most commonly spoken on the planet, and most multilingual workers will find the language support useful.

What Speechnotes Is Missing

Speechnotes does not offer the ability to delete typos with a verbal command. So if you accidentally say something you don’t want in your text, you will have to use your keyboard to make the correction. If you want full control over editing your text, then Dragon is worth a look as that platform allows you to make deletions as well as navigate through your text quickly and easily.

Users find Speechnotes to be an effective solution, especially for a free app. The fact that you can start dictating without even making an account is appreciated by customers. With that in mind, there are several complaints about the software’s ability to understand uncommon names.

How We Evaluated Voice Recognition Software

Voice recognition services should be able to recognize your speech and process it as an on-screen action. This can range from dictating a text document to finding information in your calendar app. However, they should also save you time compared to typing commands by hand. To determine the best, we looked at dedicated speech dictation software as well as popular smart assistants found on modern smartphones.

The criteria we used to evaluate which voice recognition software was the best included:

  • Cost – We compared the overall price of software as well as the cost of any required equipment, or subscription fees associated with using the service.
  • Ease of Use – How easy a tool is to set up and use played a large role in our evaluation.
  • Accuracy – To determine the best, we compared how accurate each software is in translating your spoken words into on-screen text and commands.
  • Dictation Features – We compared each product’s ability to understand common commands helpful in the writing and editing of documents.
  • App and OS control – Voice commands for opening apps, setting reminders, and getting weather information through verbal commands were also considered.
  • Language Support – We reviewed the number of languages that the software is capable of recognizing and speaking.
  • Operating System – Many voice recognition programs support only a limited number of platforms. We therefore we looked for products that could serve the largest number of users.
  • Built-in Intelligence – Additional benefits such as artificial assistance offered by each tool were also considered.

Based on the criteria above, we find that Dragon is the best voice recognition software for small business users. It allows you to dictate text as well as control apps on your PC workstation with the most accuracy on the market today. While the product offers limited-to-no support for Mac users, we find that most business users looking to add voice recognition technology would benefit from having Dragon installed on their machine.

Picking a Python Speech Recognition Package#

A handful of packages for speech recognition exist on PyPI. A few of them include:

  • apiai
  • assemblyai
  • google-cloud-speech
  • pocketsphinx
  • SpeechRecognition
  • watson-developer-cloud
  • wit

Some of these packages—such as wit and apiai—offer built-in features, like natural language processing for identifying a speaker’s intent, which go beyond basic speech recognition. Others, like google-cloud-speech, focus solely on speech-to-text conversion.

There is one package that stands out in terms of ease-of-use: SpeechRecognition.

Recognizing speech requires audio input, and SpeechRecognition makes retrieving this input really easy. Instead of having to build scripts for accessing microphones and processing audio files from scratch, SpeechRecognition will have you up and running in just a few minutes.

The SpeechRecognition library acts as a wrapper for several popular speech APIs and is thus extremely flexible. One of these—the Google Web Speech API—supports a default API key that is hard-coded into the SpeechRecognition library. That means you can get off your feet without having to sign up for a service.

The flexibility and ease-of-use of the SpeechRecognition package make it an excellent choice for any Python project. However, support for every feature of each API it wraps is not guaranteed. You will need to spend some time researching the available options to find out if SpeechRecognition will work in your particular case.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *