百度语音识别异常_百度语音识别和语音合成实战

概述

随着人工智能的普及,越来越多的产品希望在现阶段增加语音功能。然而,语音识别并不是那么容易,所以各大互联网巨头都推出了语音识别产品。本文主要介绍了百度的语音识别和语言合成功能。

[En]

With the popularity of artificial intelligence, more and more products want to add voice function at this stage. However, speech recognition is not so easy, so the major Internet giants have launched speech recognition products. This article mainly introduces Baidu’s speech recognition and language synthesis functions.

要使用百度的语言功能,需要注册百度云账号,登录百度云,选择百度产品的‘人工智能’,点击‘语言识别’。

[En]

To use Baidu’s language function, you need to sign up for a Baidu Cloud account, log in to Baidu Cloud, select the ‘artificial intelligence’ of Baidu products, and click ‘language recognition’.

点击后显示下面的页面

可以看到有两个按钮,’立即使用’和’技术文档’

我们可以首先构建一个语音产品应用程序,然后单击“立即使用”

[En]

We can first build a voice product application and click ‘use now’

如果它以前没有创建过,则有0个应用程序。您可以先创建应用程序。

[En]

If it has not been created before, then there are 0 applications. You can create applications first.

在此页面上填写您的应用程序名称和应用程序类型,然后选择应用程序的功能。创建完成后,它将生成

[En]

Fill in your application name and application type on this page, and then select the function of the application. When the creation is completed, it will generate

AppID,API Key,Secret Key,把这三个参数需要记录下来。

再打开百度的语音文档

百度的语音识别API是REST API接口,可以使用任意语言来使用。同时百度还提供了多种常见的编程语言的API。我们以python为例子来演示百度的语言识别和语言合成过程.

语音识别

使用python的百度语音识别,需要下载百度的语音SDK包

执行下面命令:pip install baidu-aip

output.wav是使用录音软件录下的16000采样率单声道的语音文件。

from aip import AipSpeechimport wavedef get_pcm_from_wav(filename):wav = wave.open(filename,’rb’)return wav.readframes(wav.getnframes())APP_ID = ‘你自己的AppID’APP_KEY = ‘你自己的app key’SECRET_KEY = ‘你自己的Secret Key’client = AipSpeech(APP_ID,APP_KEY,SECRET_KEY)pcm_con = get_pcm_from_wav(‘output.wav’)res = client.asr(pcm_con,’pcm’,16000,{‘dev_pid:’:1536})print(res)

执行python asr_test.py

输出:

{‘corpus_no’: ‘6763268067273881154’, ‘sn’: ‘172374735471574696057’, ‘err_no’: 0, ‘err_msg’: ‘success.’, ‘result’: [‘这是一个语音测试’]}

语音合成

使用百度的语音合成很简单,稍微修改一下上面的代码:

[En]

Using Baidu’s speech synthesis is very simple, change the above code slightly:

from aip import AipSpeechimport osAPP_ID = ‘你自己的AppID’

APP_KEY = ‘你自己的app key’

SECRET_KEY = ‘你自己的Secret Key’

client = AipSpeech(APP_ID,APP_KEY,SECRET_KEY)result = client.synthesis(‘请把我的文字直接播放’,’zh’,1,{‘vol’:5})if not isinstance(result,dict):with open(‘tts.mp3′,’wb’) as f:f.write(result)os.system(‘play tts.mp3’)

执行python3 tts_test.py

此时,电脑上就可以播放一句《请直接播放我的文字》。

[En]

At this time, the sentence “Please play my text directly” can be played on the computer.

上面的代码在ubuntu16.04下面都调试通过。

郑重声明:本作品为原创,如转载,须注明出处:《标题:物联网电子世界》

[En]

Solemnly declare: this work is original, if reprinted, it must indicate the source “headline: Internet of things Electronic World”

Original: https://blog.csdn.net/weixin_39736379/article/details/113326978
Author: weixin_39736379
Title: 百度语音识别异常_百度语音识别和语音合成实战

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/515456/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球