Skip to main content

tts

概述

基于讯飞TTS语音合成API的文字转语音功能,将文字信息转化为声音信息,给掌控板配上“嘴巴”。其合成音在音色、自然度等方面的表现均接近甚至超过了人声。目前应用于掌控拓展板。

库的安装方法

可通过以下任一方法进行安装。

  1. 将项目中的tts.py 和依赖于base64.py拷到掌控板文件系统上
  2. 在掌控板REPL界面中,使用upip安装,步骤如下:
    • 前置条件需要掌控板连接网络
    • 导入upip模块,执行import upip
    • 执行`upip.install('mPython-tts')
>>> import upip
>>> upip.install('mPython-tts')

使用

该功能使用讯飞的在线语音合成服务,需要用户自行在在讯飞开发平台 https://www.xfyun.cn/ 注册账号,步骤如下:

  1. 注册账号
  2. 新建产品,选择“在线语音合成”服务。
  3. 在IP白名单中添加网络的公网IP。

示例:

from mpython import * 
from tts import *

mywifi=wifi()
mywifi.connectWiFi('ssid','password')   #连接 WiFi 网络

APPID = ""                              # 讯飞应用ID
API_KEY = ""                            # 讯飞应用的api key


tts=TTS(APPID,API_KEY)                  #构建TTS实例,并传入appid,api key 参数.

# 沁园春·长沙 诗词
poem=   "独立寒秋,湘江北去,橘子洲头。  \
        看万山红遍,层林尽染;漫江碧透,百舸争流。\
        鹰击长空,鱼翔浅底,万类霜天竞自由。\
        怅寥廓,问苍茫大地,谁主沉浮?\
        携来百侣曾游。忆往昔峥嵘岁月稠。\
        恰同学少年,风华正茂;书生意气,挥斥方遒。\
        指点江山,激扬文字,粪土当年万户侯。\
        曾记否,到中流击水,浪遏飞舟?"\


tts.translate(poem)                      # 文字转语音并播放

执照

所有代码均在MIT许可下发布。

Release files for mPython-tts 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mPython-tts 0.1.0
File Size Uploaded
mPython-tts-0.1.0.tar.gz 3.4 kB Details

Release files / mPython-tts-0.1.0.tar.gz

Download URL mPython-tts-0.1.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7a7a721c2166d7204e4a547f3a9ec9637155cdc03d1952a9d77cfbe4159bad81
BLAKE2b-256 checksum
How to use checksums
67796b0cbcfd943157680a8d75a031264e93f905510e74599e279a3b332a3725
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page