Tts
– 文字合成语音(Text to Speech)引擎
Tts模块实现HaaS平台的文本语音合成功能,配合阿里云后台实现端上Text上报云端并生成URL音频链接。具体接口和参数如下所示。
调用Recorder接口之前,你需要先完成声卡及Audio引擎的初始化工作,具体接口请参考 Snd
模块
使用示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 | # coding=utf-8
from audio import Tts
# 实例化音频合成引擎并创建Tts句柄
t0 = Tts()
t0.create()
#配置Tts语音合成相关信息
t0.init(0, {'app_key': 'ClHu********DJYN',
'token': 'f3f15b********************55270d',
'format': 3,
'sample_rate': 16000,
'voice': 'siqi',
'volume': 80,
'speech_rate': 0,
'pitch_rate':0,
'text_encode_type': 1})
#设置Tts回调类型及回调函数
def cb_url(url):
print("receive url = %s" %(url))
t0.callback(t0.CB_ENUM_URL, cb_url)
#发起语音合成请求
t0.request('我爱你, micropython轻应用!', 0)
#释放Tts引擎资源
p0.release()
|
函数常量
-
Tts支持的回调类型:
-
CB_ENUM_URL
-
CB_ENUM_DATA
-
CB_ENUM_EVENT
函数接口
Tts模块具体接口和参数如下所示。
-
Tts.
create
()[源代码]
创建TTS引擎。
- 参数
空 –
- 返回
0: 成功,其他: 失败
- 引发
OSError – 空
-
Tts.
release
()[源代码]
释放TTS引擎。
- 参数
空 –
- 返回
0: 成功,其他: 失败
- 引发
OSError – EINVAL
-
Tts.
callback
(type, cbfun)[源代码]
设置TTS的回调类型及回调函数。示例:
def cb_url(test):
print("receive info with url %s" %(test))
t0.callback(t0.CB_ENUM_URL, cb_url)
- 参数
-
- 返回
0: 成功,其他: 失败
- 引发
OSError – EINVAL
-
Tts.
init
(aicloud_type, config)[源代码]
初始化Tts引擎配置,详细信息参考 语音合成接口说明 。示例:
t0.init(0, {'app_key': 'xxxxx',
'token': 'xxxxxxxx',
'format': 3,
'sample_rate': 16000,
'voice': 'siqi',
'volume': 80,
'speech_rate': 0,
'pitch_rate':0,
'text_encode_type': 1})
- 参数
-
- 返回
0: 成功,其他: 失败
- 引发
OSError – EINVAL
-
Tts.
request
(text, recv_type)[源代码]
发起Tts语音合成请求。
- 参数
-
- 返回
0: 成功,其他: 失败
- 引发
OSError – ENXIO
-
Tts.
stop
()[源代码]
停止Tts语音合成请求。
- 参数
空 –
- 返回
0: 成功,其他: 失败
- 引发
OSError – EINVAL