博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python speech_使用Google Speech API进行Python语音识别
阅读量:2508 次
发布时间:2019-05-11

本文共 3455 字,大约阅读时间需要 11 分钟。

python speech

In this tutorial you will learn about python speech recognition. There are plenty of options available for this. But Google Speech API is best among all of them.

在本教程中,您将学习python语音识别。 有很多可用的选项。 但是,Google Speech API是其中最好的。

So in this article we are going to see how we can implement Google Speech API in Python.

因此,在本文中,我们将了解如何在Python中实现Google Speech API。

所需的安装文件 (Required Installation Files)

1. Install  PyAudio

1.安装PyAudio

PyAudio provides Python bindings for Port Audio, the cross-platform audio I/O library. With PyAudio, you can easily use Python to play and record audio on a variety of platforms. To install PyAudio open terminal or command prompt and type this command and hit enter. 

PyAudio为跨平台音频I / O库Port Audio提供Python绑定。 使用PyAudio ,您可以轻松地使用Python在各种平台上播放和录制音频。 要安装PyAudio,请打开终端或命令提示符,然后键入此命令,然后按Enter。  

For linux:

对于Linux:

sudo apt-get install python-pyaudio python3-pyaudio 

须藤apt-get install python-pyaudio python3-pyaudio  

For windows:

对于Windows:

pip install PyAudio

pip安装PyAudio

This command will install PyAudio for both Python 2 and Python 3.

此命令将为Python 2和Python 3安装PyAudio。

Also Read: 

另请阅读:

2. Install Python Speech Recognition Module

2.安装Python语音识别模块

It is a Library for performing speech recognition, with support for several engines and APIs, online and offline. To install it open terminal or command prompt, type the command  mentioned below and hit enter.

它是一个用于执行语音识别的库,支持在线和离线的多个引擎和API。 要安装它,请打开终端或命令提示符,键入以下提到的命令,然后按Enter。

pip install SpeechRecognition

点安装语音识别

Python语音识别程序 (Python Speech Recognition Program)

import speech_recognition as sr r = sr.Recognizer()with sr.Microphone() as source:    print("Say something!")    audio = r.listen(source)try:    text = r.recognize_google(audio)    print("You said: " + text)except sr.UnknownValueError:    print("Google Speech Recognition could not understand audio")except sr.RequestError as e:    print("Could not request results from Google Speech Recognition service" + format(e))

Output

输出量

Say something!

说些什么!

You said: hello how are you

你说:你好

I have said “hello are you”. That’s why it is printing the same. You can speak anything you want and  this program will record your audio and convert it into text and print it on the screen.

我说过“你好”。 这就是为什么要打印相同的原因。 您可以说任何话,该程序将录制您的音频并将其转换为文本并在屏幕上打印。

Isn’t it awesome.

是不是很棒

Now let’s understand the program.

现在让我们了解程序。

In first line we’re just importing the package speech_recognition as sr. Then we are making a object of class Recognizer to use the methods listen() and recognize_google(). Class Microphone is used to use the default microphone as the audio source.

在第一行中,我们只是将包Speech_recognition导入为sr。 然后,我们使Recognizer类的对象使用方法listen()ognize_google()。 Class Microphone用于将默认麦克风用作音频源。

listen() method will listen for the first phrase and extract it into audio data.

listen()方法将侦听第一个短语并将其提取到音频数据中。

Then we’ll pass that audio in recognize_google() method and this method will return the text generated from that audio.

然后,我们将该音频传递到accept_google ()方法中,该方法将返回从该音频生成的文本。

The reason to put recognize_google method into try – except statements is that if any error  occur while recognizing it then  we can print that error using except.

尝试identify_google方法放入except语句的原因是,如果在识别它时发生任何错误,则可以使用except打印该错误。

Note: Internet connection will be needed while running this program.

注意:运行该程序时需要Internet连接。

Comment down below if you have any queries related to python speech to text tutorial.

如果您对python语音文本教程有任何疑问,请在下面注释掉。

翻译自:

python speech

转载地址:http://oxggb.baihongyu.com/

你可能感兴趣的文章
第八章 springboot + mybatis + 多数据源
查看>>
Arab and North African Region,2002(Snakes & ladders)
查看>>
React中的Refs
查看>>
自己使用MySQL中的GROUP_CONCAT(CONCAT_WS())函数查询的数据显示不全的问题. 以及在后台开发中怎么设置使用....
查看>>
Mysql强制修改密码
查看>>
100
查看>>
新手springmvc web简单搭建过程-caidachun
查看>>
Inline Edit
查看>>
Mybatis generator生成工具简单介绍
查看>>
sqoop 补充
查看>>
什么是好代码?
查看>>
简易五子棋AI算法分析
查看>>
2018.12.1 web项目中解决乱码问题的一个工具类
查看>>
JSP 中 forward 和 redirect 的区别_2014.12.31
查看>>
解释性语言,编译性语言,脚本语言
查看>>
26.Remove Duplicates from Sorted Array
查看>>
PSFTP用法
查看>>
React 学习一 运行
查看>>
Unity - Photon PUN 本地与网络同步的逻辑分离 (二)
查看>>
Asp.Net基础 - 6.Cookie + 7.Session原理
查看>>