jing332 / tts-server-android

这是一个Android系统TTS应用,内置微软演示接口,可自定义HTTP请求,可导入其他本地TTS引擎,以及根据中文双引号的简单旁白/对话识别朗读 ,还有自动重试,备用配置,文本替换等更多功能。
3.13k stars 256 forks source link

custom http request syntax issue? #100

Closed LuekWasHere closed 1 year ago

LuekWasHere commented 1 year ago

Hello I unfortunately don't speak Chinese so this language barrier might make communication difficult, I will do my best to communicate clearly. I am attempting to make a custom http request using the tts-server-android application. Im running a Opentts server which allows me to run a neural net tts offline and make https requests to it. The tts is excellent. It works somewhat well with your application. Though it seems during the encoding of the text from your tts app it seems to have a syntax conflict with the actual raw text (causing the text to be parsed incorrectly).

翻译 您好,我不会说中文,所以语言障碍可能会使沟通变得困难,但我会尽力清晰地表达。我正在尝试使用 tts-server-android 应用程序进行自定义 http 请求。我正在运行一个 Opentts 服务器,它允许我离线运行一个神经网络 tts 并对其进行 https 请求。这个 tts 非常出色。它与您的应用程序配合得相当好。不过,在您的 tts 应用程序对文本进行编码时似乎与实际的原始文本存在语法冲突(导致文本解析不正确)。

// Example of failure from log 日志中失败的示例:

<br>Request audio: <b>from an intelligence explosion (Good 1965): a process in which software based intelligent minds enter a runaway reaction of self improvement cycles, with each new and more intelligent generation appearing faster than its predecessor.</b><br> <i><small>HttpTTS(url=http://192.168.0.226:5500/api/tts?voice=larynx%3Acmu_aew-glow_tts&text={{java.encodeURI(speakText)}}&vocoder=low&denoiserStrength=0&cache=true , header=, pitch=1, volume=50, rate=0, audioFormat=16000hz | decode, audioPlayer=PlayerParams(rate=0.0, pitch=0.0, volume=0.0), audioParams=AudioParams(speed=2.13, volume=1.0, pitch=1.19), speechRule=SpeechRuleInfo(target=0, isStandby=false, tag=, tagRuleId=, tagName=, tagData={}, configId=1689134740002))</small></i>

has a log output of 具有日志输出:

Failed: (1) cc.l: Expected start of the object '{', but had 'EOF' instead at path: $ JSON input: %20with%20each%20new%20and%20more%20intelligent%20generation%20appearing%20faster%20than%20its%20predecessor.&vocoder=low&denoiserStrength=0&cache=true

// Example of successful parse from log 日志中成功解析的示例:

<br>Request audio: <b>Part I of this volume is dedicated to essays which argue that progress in artificial intelligence and machine learning may indeed increase machine intelligence beyond that of any human being.</b><br> <i><small>HttpTTS(url=http://192.168.0.226:5500/api/tts?voice=larynx%3Acmu_aew-glow_tts&text={{java.encodeURI(speakText)}}&vocoder=low&denoiserStrength=0&cache=true , header=, pitch=1, volume=50, rate=0, audioFormat=16000hz | decode, audioPlayer=PlayerParams(rate=0.0, pitch=0.0, volume=0.0), audioParams=AudioParams(speed=2.13, volume=1.0, pitch=1.19), speechRule=SpeechRuleInfo(target=0, isStandby=false, tag=, tagRuleId=, tagName=, tagData={}, configId=1689134740002))</small></i>

I hope this makes sense. I've tried changing the url in many ways. Though these still seems to be a conflict with only specific raw texts. If you have any ideas on how i could change this url input to avoid the conflict with the raw text, please let me know. 我希望这能讲得通。我尝试过以多种方式更改 url。不过,似乎仍然只有特定的原始文本存在冲突。 如果您有任何关于如何更改此 url 输入以避免与原始文本冲突的想法,请告诉我。

Thank you 谢谢, Lewk

jing332 commented 1 year ago

Custom HTTP TTS is deprecated, you can use the more powerful JavaScript plugin functionality.

jing332 commented 1 year ago

This is an example of Baidu TTS plugin if you have any doubts, please ask questions.

🙂Click here to collapse/expand > Plugin Manager -> ADD Button ``` javascript let PluginJS = { 'name': '百度', 'id': 'tsn.baidu.com', 'author': '🙂', 'description': 'Plugin for Baidu Text-to-Speech service', 'version': 1, 'getAudio': function(text,locale, voice, speed, volume, pitch) { let spd = Math.round(speed * 15 / 100) let vol = Math.round(volume * 15 / 100) let pit = Math.round(pitch * 15 / 100) let per = voice // encode text and build request body let encText = encodeURIComponent(text) let reqParams = `?tex=${encText}&spd=${spd}&vol=${vol}&pit=${pit}&per=${per}&cuid=baidu_speech_demo&idx=1&cod=2&lan=zh&ctp=1&pdt=220&aue=3&res_tag=audio` // make request to TTS API let reqUrl = 'http://tsn.baidu.com/text2audio' + reqParams let reqHeaders = { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' } return ttsrv.httpGet(reqUrl, reqHeaders).body().byteStream() } } let locales = ['zh'] let voices = { 'zh': { '1': '度小宇', '0': '度小美', '3': '度逍遥(基础)', '4': '度丫丫', '4003': '度逍遥真品', '5118': '度小鹿', '106': '度博文', '110': '度小童', '111': '度小萌', '103': '度米朵', '5': '度小娇', '4118': '杜小璐真品', '4119': '杜小璐温柔', '4100': '小杜(默认)', '4103': '小度(儿童模式)', '4105': '小肚(甜而不腻女友音)', '4106': '杜博文珍品', '4114': '百度评书', '4115': '杜小贤', '4117': '度小桥', '4121': '百度青年男生' } } let EditorJS = { 'getAudioSampleRate': function(locale, voice) { let audio = PluginJS.getAudio('测试test', 'zh', voice, 50, 50, 50) return ttsrv.getAudioSampleRate(audio) }, 'onLoadData': function() { }, 'getLocales': function() { return locales }, 'getVoices': function(locale) { return voices[locale] }, 'onLoadUI': function(ctx, linearLayout) { } } ```
jing332 commented 1 year ago

You can modify the HTTP request parameters according to your needs :

let reqParams = `?voice=larynx%3Acmu_aew-glow_tts&text=${encText}&vocoder=low&denoiserStrength=0&cache=true`

Full plugin code:

Add Plugin -> replace code -> Save -> Enable OpenTTS

let PluginJS = { 'name': 'OpenTTS', 'id': 'opentts.com', 'author': 'TTS Server', 'version': 1,

'getAudio': function(text,locale, voice, speed, volume, pitch) { let encText = encodeURIComponent(text) let reqParams = ?voice=larynx%3Acmu_aew-glow_tts&text=${encText}&vocoder=low&denoiserStrength=0&cache=true

    // make request to TTS API
    let reqUrl = 'http://192.168.0.226:5500/api/tts' + reqParams

    let reqHeaders = {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }

    return ttsrv.httpGet(reqUrl, reqHeaders).body().byteStream()
} 

}

let locales = ['en'] let voices = { 'en': { '1': 'voice1', } }

let EditorJS = { 'getAudioSampleRate': function(locale, voice) { let audio = PluginJS.getAudio('sampletext', 'en', voice, 50, 50, 50) return ttsrv.getAudioSampleRate(audio) },

'onLoadData': function() {

},

'getLocales': function() {
    return locales
},

'getVoices': function(locale) {
  return voices[locale]
},

'onLoadUI': function(ctx, linearLayout) {

}

}

jing332 commented 1 year ago

Like this:


LuekWasHere commented 1 year ago

哇,你的帮助让我感到震惊。我非常感激。我可以保证这个工作很好,我现在有一个离线TTS,它的工作效果非常好。我真的很喜欢学习新东西,你做得很好,让我受益匪浅。我将想办法将Opentts api纳入其他方面(例如能够更改语音),以及在树莓派或其他可持续性设备上运行TTS服务器。你太棒了。