温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用python脚本进行文本转换的方法

发布时间:2020-11-13 10:05:40 来源:亿速云 阅读:300 作者:小新 栏目:编程语言

小编给大家分享一下使用python脚本进行文本转换的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

语音识别通常有以下流程:

接收语音,比如通过电话等方式

对接收到的语音做处理,将声音转化为电子信号

通过模拟数字转换器将模拟形式的连续电子信号转换为数字形式的离散信号

转换成数字信号后,模型便可以将音频转换为文本了

Python 库

pip install SpeechRecognition

将音频文件转换为文本

导入语音识别库

初始化识别类,以便识别语音。

支持语音识的音频文件格式:wav, AIFF, AIFF-C, FLAC Wav,AIFF,AIFF-c,FLAc.在这个例子中我们使用wav文件.

我用的是一段电影音频剪辑,里边说的话是:"I don’t know who you are,I don’t know what you want, if you’re looking for ransom,I can tell you I don’t have money"

默认情况下,谷歌识别器读取的是英语。

具体代码如下所示:

#import library
import speech_recognition as sr
 
# Initialize recognizer class (for recognizing the speech)
r = sr.Recognizer()
 
# Reading Audio file as source
# listening the audio file and store in audio_text variable
 
with sr.AudioFile('I-dont-know.wav') as source:
    
    audio_text = r.listen(source)
    
# recoginize_() method will throw a request error if the API is unreachable, hence using exception handling
    try:
        
        # using google speech recognition
        text = r.recognize_google(audio_text)
        print('Converting audio transcripts into text ...')
        print(text)
     
    except:
         print('Sorry.. run again...')

以上是使用python脚本进行文本转换的方法的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI