Socket
Book a DemoInstallSign in
Socket

bce-text2audio-cli

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bce-text2audio-cli

Call baidu cloud apis to convert text to audio

1.0.2
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

BCE Text2Audio Cli

懒得看文字,但 macOS 的 speech 语音质量太差,所以封装了一个百度开放云的语音合成接口的工具,可以把一大段文字转成音频。

npm install -g bce-text2audio-cli
bce-text2audio-cli < article.txt

BCE控制台 创建一个应用(免费语音合成额度每天20万次,自己使用足够了)。然后新建 ~/.bce-text2audio-cli-config.json,填入:

{
    "APP_ID": "________",
    "API_KEY": "______________",
    "SECRET_KEY": "_______________"
}

因为接口单次调用有文本长度的限制,所以切割了一下文本,多次调用得到很多个 mp3 文件,保存在 /tmp/ 下。因为在 js 里做 mp3 合并有点麻烦,所以运行后输出一个 FFmpeg 的命令,复制一下跑这个命令让 ffmpeg 帮忙做合并的工作啦。

支持参数:

  • --concurrency=2 接口并发请求个数
  • --input-file 指定文本文件。或者从标准流输入
  • --clean [--dryrun] 删除临时文件

命令还支持语音合成接口的几个参数:

参数类型描述是否必须
spdString语速,取值0-9
pitString音调,取值0-9
volString音量,取值0-15
perString发音人选择, 0为女声,1为男声,3为情感合成-度逍遥,4为情感合成-度丫丫

macOS 用户可以使用 Automator 新建一个 Service,接收文本,添加一个 "Run Shell Script" 模块,贴入代码:

bce-text2audio-cli --spd 5 --vol 9 < /dev/stdin | tail -n2 | head -n1 | grep ffmpeg | cut -d'|' -f 2 | awk '{$1=$1};1' | cut -d' ' -f 1-9 | awk "{print \$0 \" ~/Downloads/`date +%s`.mp3\"}" | bash -

这样在系统里选中文字,右键菜单里启动这个服务就能把选中的文本变成音频。

FAQs

Package last updated on 11 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.