Create POST /{format} endpoint (file.lua)
This commit is contained in:
@@ -27,7 +27,8 @@ class TTSLibrary(private val ttsEngine: TTSEngine) : TwoArgFunction() {
|
|||||||
|
|
||||||
class SayMethod(private val ttsEngine: TTSEngine) : TwoArgFunction() {
|
class SayMethod(private val ttsEngine: TTSEngine) : TwoArgFunction() {
|
||||||
override fun call(text: LuaValue, language: LuaValue): LuaValue {
|
override fun call(text: LuaValue, language: LuaValue): LuaValue {
|
||||||
ttsEngine.performTTS(text.checkjstring(), Locale.forLanguageTag(language.checkjstring()))
|
val locale = Locale.forLanguageTag(language.checkjstring().toUpperCase(Locale.ROOT))
|
||||||
|
ttsEngine.performTTS(text.checkjstring(), locale)
|
||||||
|
|
||||||
return LuaValue.NIL
|
return LuaValue.NIL
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ class ScriptsInitializer(private val context: Context, private val preferences:
|
|||||||
companion object {
|
companion object {
|
||||||
private const val INITIALIZED_FLAG = "flag_initialized"
|
private const val INITIALIZED_FLAG = "flag_initialized"
|
||||||
private val endpoints = mapOf(
|
private val endpoints = mapOf(
|
||||||
"say.lua" to R.raw.say
|
"say.lua" to R.raw.say,
|
||||||
|
"file.lua" to R.raw.file
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,2 +1,19 @@
|
|||||||
|
local silenceModeTimeRange = {
|
||||||
|
from = { 23, 00 },
|
||||||
|
to = { 07, 00 }
|
||||||
|
}
|
||||||
|
|
||||||
|
function silenceMode()
|
||||||
|
local date = os.date("*t")
|
||||||
|
|
||||||
|
local from = silenceModeTimeRange.from[1] * 60 + silenceModeTimeRange.from[2]
|
||||||
|
local to = silenceModeTimeRange.to[1] * 60 + silenceModeTimeRange.to[2]
|
||||||
|
local now = date.hour * 60 + date.min
|
||||||
|
|
||||||
|
if (from <= to) then return from <= now and now <= to
|
||||||
|
else return from <= now or now <= to end
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
silenceMode = silenceMode
|
||||||
}
|
}
|
||||||
18
app/src/main/res/raw/file.lua
Normal file
18
app/src/main/res/raw/file.lua
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
return {
|
||||||
|
uri = "/{format}",
|
||||||
|
method = Method.POST,
|
||||||
|
accepts = Mime.JSON,
|
||||||
|
consumer = function(request)
|
||||||
|
local body = json.decode(request.body)
|
||||||
|
local format = (request.params.format or "WAV"):upper()
|
||||||
|
local audioFormat = AudioFormat[format]
|
||||||
|
local mime = Mime[format]
|
||||||
|
|
||||||
|
local file = tts.sayToFile(body.text, body.language or "en", audioFormat)
|
||||||
|
|
||||||
|
return {
|
||||||
|
mime = mime,
|
||||||
|
data = file
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
@@ -2,8 +2,11 @@ return {
|
|||||||
uri = "/say",
|
uri = "/say",
|
||||||
method = Method.POST,
|
method = Method.POST,
|
||||||
queued = true,
|
queued = true,
|
||||||
accepts = "application/json",
|
accepts = Mime.JSON,
|
||||||
consumer = function()
|
consumer = function(request)
|
||||||
tts.say("Hello, world!", "en")
|
if(config.silenceMode()) then return end
|
||||||
|
|
||||||
|
local body = json.decode(request.body)
|
||||||
|
tts.say(body.text, body.language or "en")
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user