feat: add termux tts support

This commit is contained in:
JuanZoran
2023-04-02 11:01:37 +08:00
parent 9357574b5c
commit 576f1eb66a
5 changed files with 38 additions and 30 deletions

View File

@ -1,34 +1,39 @@
local api, fn = vim.api, vim.fn
--- INFO :Define plugin command
local Trans = require("Trans")
local Trans = require 'Trans'
local command = api.nvim_create_user_command
command("Translate", function()
command('Translate', function()
Trans.translate()
end, { desc = " Translate cursor word" })
end, { desc = ' Translate cursor word' })
command("TranslateInput", function()
Trans.translate({ mode = 'i' })
end, { desc = " Translate input word" })
command('TranslateInput', function()
Trans.translate { mode = 'i' }
end, { desc = ' Translate input word' })
command("TransPlay", function()
command('TransPlay', function()
local util = Trans.util
local str = util.get_str(vim.fn.mode())
if str and str ~= "" and util.is_English(str) then
if str and str ~= '' and util.is_English(str) then
str:play()
end
end, { desc = " Auto play" })
end, { desc = ' Auto play' })
string.width = api.nvim_strwidth
local system = Trans.system
local f =
fn.has('linux') == 1 and ([[echo %q | festival --tts]])
or fn.has('mac') == 1 and ([[say %q]])
or 'node' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q'
system == 'mac' and 'say %q' or
system == 'termux' and 'termux-tts-speak %q' or
system == 'linux' and 'echo %q | festival --tts' or
'node' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q'
-- 'powershell -Command "Add-Type AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak([Console]::In.ReadToEnd())" | Out-File -Encoding ASCII %q'
-- or 'node' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q'
-- system == 'win' and 'powershell -Command "Add-Type AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak([Console]::In.ReadToEnd())" | Out-File -Encoding ASCII %q'
string.play = function(self)
fn.jobstart(f:format(self))
end