GithubHelp home page GithubHelp logo

wxxxcxx / ms-ra-forwarder Goto Github PK

View Code? Open in Web Editor NEW
820.0 9.0 771.0 157 KB

免费的在线文本转语音API

Home Page: https://ms-ra-forwarder.vercel.app

License: MIT License

TypeScript 52.68% HTML 46.62% Dockerfile 0.70%
tts tts-api

ms-ra-forwarder's Introduction

部署

请参考下列部署方式。

部署到 Vercel

Deploy with Vercel

请先 Fork 一份代码然后部署到自己的 Vercel 中 。参考 演示视频

部署到 Railway

Railway 增加了每个月500小时的限制,而且不会自动停机,所以每个月会有一段时间无法是使用。有条件的还是使用docker部署吧。

Deploy on Railway

部署到 Heroku

Deploy

Docker(推荐)

需要安装 docker。

# 拉取镜像
docker pull wxxxcxx/ms-ra-forwarder:latest
# 运行
docker run --name ms-ra-forwarder -d -p 3000:3000 wxxxcxx/ms-ra-forwarder
# or
docker run --name ms-ra-forwarder -d -p 3000:3000 -e TOKEN:自定义TOKEN wxxxcxx/ms-ra-forwarder

# 浏览器访问 http://localhost:3000

Docker Compose

创建 docker-compose.yml 写入以下内容并保存。

version: '3'

services:
  ms-ra-forwarder:
    container_name: ms-ra-forwarder
    image: wxxxcxx/ms-ra-forwarder:latest
    restart: unless-stopped
    ports:
      - 3000:3000
    environment:
      # 不需要可以不用设置环境变量
      - TOKEN=自定义TOKEN

docker-compose.yml 目录下执行 docker compose up -d

手动运行

手动运行需要事先安装好 git 和 nodejs。

# 获取代码
git clone https://github.com/wxxxcxx/ms-ra-forwarder.git

cd ms-ra-forwarder
# 安装依赖
npm install 
# 运行
npm run start

使用

导入到阅读(legado)

请访问你部署好的网站,在页面中测试没有问题后点击“生成阅读(legado)语音引擎链接”,然后在阅读(legado)中导入。

手动调用

接口地址为api/ra。格式为:

POST /api/ra
FORMAT: audio-16khz-128kbitrate-mono-mp3
Content-Type: text/plain

<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="en-US">
  <voice name="zh-CN-XiaoxiaoNeural">
    如果喜欢这个项目的话请点个 Star 吧。
  </voice>
</speak>

定制发音和音色

请求的正文为 ssml 格式,支持定制发音人和讲话风格(目前仅 Azure 版本支持定制讲话风格),下面是相关的示例和文档:

文本转语音

通过语音合成标记语言 (SSML) 改善合成

音频格式

默认的音频格式为 webm ,如果需要获取为其他格式的音频请修改请求头的 FORMAT(可用的选项可以在 ra/index.ts 中查看)。

限制访问

如果需要防止他人滥用你的部署的服务,可以在应用的环境变量中添加 TOKEN,然后在请求头中添加 Authorization: Bearer <TOKEN>访问。

其他说明

  • 微软官方的 Azure TTS 服务目前拥有一定的免费额度,如果免费额度对你来说够用的话,请支持官方的服务。

  • 如果只需要为固定的文本生成语音,可以使用有声内容创作。它提供了更丰富的功能可以生成更自然的声音。

  • 本项目使用的是 Edge 浏览器“大声朗读”和 Azure TTS 演示页面的接口,不保证后续可用性和稳定性。

  • 本项目仅供学习和参考,请勿商用。

重要更改

2023-04-19:Azure 下线了演示页面的试用功能,导致 Azure 版接口无法使用了,请各位迁移到 Edge 浏览器的接口吧。

2022-11-18:添加词典文件支持,词典文件格式参考 https://github.com/wxxxcxx/azure-tts-lexicon-cn/blob/main/lexicon.xml

2022-09-10:修改 docker 仓库地址,后面构建的 docker 镜像会迁移到 wxxxcxx/ms-ra-forwarder(原仓库旧版本镜像依然有效)。

2022-09-01:Azure TTS API 好像又改了,旧版用户可能会无法正常使用,请更新到最新版。

2022-07-17:添加 Azure TTS API 支持(没怎么测试,不知道用起来稳不稳定)。因为调用 Azure TTS API 需要获取授权码。其它方式只需要或取一次就可以使用一段时间,而 Vercel 每次调用 API 都需要重新获取授权码。容易超时不说,也加剧了微软服务器的负担,所以不是很推荐部署在 Vercel 的用户使用(虽然也不是不能用~但是万一微软被薅痛了,又改接口就不好了😂)。

2022-07-02:Edge 版本的 API 目前测试还支持的格式有 webm-24khz-16bit-mono-opuaudio-24khz-48kbitrate-mono-mp3audio-24khz-96kbitrate-mono-mp3。另外今天下午开始,使用不在下拉列表中声音会出现类似 “Unsupported voice zh-CN-YunyeNeural.” 错误,后续可能也会被砍掉。且用且珍惜吧!

2022-07-01:部署在**大陆以外服务器上的服务目前只能选择 webm-24khz-16bit-mono-opus 格式的音频了! 所以使用 Vercel 的用户需要重新部署一下。

2022-06-16:Edge 浏览器提供的接口现在已经不能设置讲话风格了,若发现不能正常使用,请参考 #12 获取更新。

感谢以下组织/个人对本项目的支持

ms-ra-forwarder's People

Contributors

ag2s20150909 avatar shenghuang147 avatar simpleandstupid avatar wxxxcxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ms-ra-forwarder's Issues

azure erros

{"message":"服务器多次尝试后转换失败","errors":["连接失败: Error: Unexpected server response: 429","连接失败: Error: Unexpected server response: 429","连接失败: Error: Unexpected server response: 429"]}

Android 阅读 APP导入注意事项

Android 阅读 APP版本:3.23.073011
ms-ra-forwarder 版本:仓库最新版

问题

ms-ra-forwarder部署在vercel上,在网页测试时是正常的,但导入阅读APP后,无法使用朗读功能,研究请求头(Header)发现凭据和音频格式没有设置进去。

代码

导入进去的请求头(Header)

{"Content-Type":"text/plain","Authorization":"Bearer ","Format":"audio-16khz-32kbitrate-mono-mp3"}

修改可用的的请求头(Header)

{"Content-Type":"text/plain","Authorization":"Bearer 凭据 ","Format":"audio-24khz-48kbitrate-mono-mp3"}

总结

在vercel网页无论怎么修改内容,导入进去都会变成{"Content-Type":"text/plain","Authorization":"Bearer ","Format":"audio-16khz-32kbitrate-mono-mp3"}

能不能出一个注册版Azure+阅读的方案

最近tts-server挺好用了,但是公共接口在某些时段延时太大经常发生中断。能不能出一个可以用注册版azure的方案。评论里面有2021年的几位大神的讨论记录,根据这些配置改了连接地址和key以后导入阅读,但是不能朗读。

安卓阅读下返回错误

电脑端本地启动后,手机访问ip+3000,在阅读(legado)中导入TTS后,点击朗读没有声音

TTS引擎的设置,能不能调整个位置?

TTS引擎的设置,能不能调整个位置?在朗读开始后,才进行设置,有点不直观,而且在切换时,因为已经在朗读了,也会容易冲突。

另外,能不能优化一下停顿的时间,无论用哪一种TTS引擎,即使我将语速调到最大,句子与句子间,段落与段落间的停顿,都非常长,对于我们这种求量不求质的读者,这个停顿还是有点烦人的~~当然,如果能进行设置,兼顾“量”与“质”的用户就最好

访问网页提示TypeError: data.forEach is not a function

已经生成的配置可以在阅读中正常使用。

访问azure版本的网页会弹出提示。

TypeError: data.forEach is not a function

azure版本的网页会出现这个提示。如图所示:
image

同时在声音的下拉提示框中,没有可用选项。如图所示:
image

大佬们,你们的还能用吗?

突然早上就不能用了,打开vercel的网站测试是还能读的,导到阅读里就不行了。大家快来试试看吧?!

端口报错。

按之前的docker-compose,出现以下报错。

Error: (HTTP code 500) server error - Ports are not available: exposing port TCP 0.0.0.0:3000 -> 0.0.0.0:0: listen tcp 0.0.0.0:3000: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

环境:Windows / docker desktop / docker-compose

docker镜像占用空间过大,修改后可节省700MB内存

docker镜像占用空间过大,我查看了项目的dockerfile

里面所使用的基础镜像是

FROM node:latest

但其实这个版本的node并不是必要的。因为这个镜像里面包含了其他的用不上的用于开发的库。
image
根据hub可以知道node-slim和node压缩包大小差距非常大。node有352.22 MB,而node-slim只有75.59 MB.
image
解压后node有990.67 MB,而node-slim只有240.47 MB。

我将node替换为node-slim后,镜像仍然运行正常,并且节省了近700MB的空间。
image

希望作者可以修改dockerfile为

FROM node:slim

npm配置上https后无法使用

在vps上docker部署
http状态可以使用
npm配置上https后
大声朗读显示: 连接失败: Error: getaddrinfo EAI_AGAIN speech.platform.bing.com
Azure 版本显示:加载失败

api转化

请问能否搭建成api访问呢?

ios源阅读下加token无效

项目不加TOKEN的时候,这种格式可以正常阅读“
https://xxxx/api/ra,{"method":"POST", "headers": {
"Format": "audio-24khz-48kbitrate-mono-mp3"
},"body":"<speak xmlns="http://www.w3.org/2001/10/synthesis\" xmlns:mstts="http://www.w3.org/2001/mstts\" xmlns:emo="http://www.w3.org/2009/10/emotionml\" version="1.0" xml:lang="en-US"><voice name="zh-CN-YunxiNeural"><prosody rate="{{(speakSpeed -1) * 2}}%" pitch="+0Hz">{{String(speakText).replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>').replace(/\/g, '')}}"}

一旦加入TOKEN变量,则显示:获取朗读音频数据为空
https://xxxx/api/ra,{"method":"POST", "headers": {
"Authorization”: “Bearer XXXXXX>”,
"Format": "audio-24khz-48kbitrate-mono-mp3"
},"body":"<speak xmlns="http://www.w3.org/2001/10/synthesis\" xmlns:mstts="http://www.w3.org/2001/mstts\" xmlns:emo="http://www.w3.org/2009/10/emotionml\" version="1.0" xml:lang="en-US"><voice name="zh-CN-YunxiNeural"><prosody rate="{{(speakSpeed -1) * 2}}%" pitch="+0Hz">{{String(speakText).replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>').replace(/\/g, '')}}"}

是请求头设置的问题吗,求教

token不太严谨的样子

虽然根据 #31 所说可以使用token了,但是生成之后的链接并不需要token就可以使用。我重新构建docker-compose之后,我发现我旧有的地址仍然能够使用。如果知道别人的网站具有这个镜像搭建的tts,理论上只需要按格式把url换成别人的,没有token一样可以用。

Azure 版本的 API 突然不可用了

2022-12-20 08:07:44 准备连接服务器……
2022-12-20 08:07:44 连接失败: Error: Unexpected server response: 401
2022-12-20 08:07:44 第1次转换失败:连接失败: Error: Unexpected server response: 401
2022-12-20 08:07:45 连接失败: Error: Unexpected server response: 401
2022-12-20 08:07:45 第2次转换失败:连接失败: Error: Unexpected server response: 401
2022-12-20 08:07:45 发生错误, 服务器多次尝试后转换失败
2022-12-20 08:07:45 Error: Unexpected server response: 401
2022-12-20 08:07:45 at ClientRequest. (/app/node_modules/ws/lib/websocket.js:877:7)
2022-12-20 08:07:45 at ClientRequest.emit (node:events:513:28)
2022-12-20 08:07:45 at HTTPParser.parserOnIncomingClient (node:_http_client:686:27)
2022-12-20 08:07:45 at HTTPParser.parserOnHeadersComplete (node:_http_common:117:17)
2022-12-20 08:07:45 at TLSSocket.socketOnData (node:_http_client:528:22)
2022-12-20 08:07:45 at TLSSocket.emit (node:events:513:28)
2022-12-20 08:07:45 at addChunk (node:internal/streams/readable:324:12)
2022-12-20 08:07:45 at readableAddChunk (node:internal/streams/readable:297:9)
2022-12-20 08:07:45 at Readable.push (node:internal/streams/readable:234:10)
2022-12-20 08:07:45 at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)
2022-12-20 08:07:45 连接已关闭: 1006
2022-12-20 08:13:04 发生错误, Request failed with status code 401
2022-12-20 08:13:14 发生错误, Request failed with status code 401
2022-12-20 08:14:39 发生错误, Request failed with status code 401

测试没效果

跟软件自带的百度TTS一样,直接就跳过了,不停的换下一段,但是没声音

docker部署部分建议补充TOKEN配置项

虽然扔服务器上,倒也不太在乎流量了,但毕竟要限制一下,滥用问题。

自己解决了,目前自用yml文件如下

docker-compose.yml

version: '3.3'
services:
    ms-ra-forwarder:
        container_name: ms-ra-forwarder
        ports:
            - '3000:3000'
        image: meetcw/ms-ra-forwarder
        restart: always
        environment:
           -TOKEN: 这里替换为自己的凭据

docker命令
docker run --name ms-ra-forwarder -d -p 3000:3000 meetcw/ms-ra-forwarder -e TOKEN:这里替换为自己的凭据

小修改,就不提PR了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.