Merge pull request #1 from ONLYOFFICE/develop

Develop
This commit is contained in:
Oleg Korshul
2020-05-28 07:02:24 +00:00
committed by GitHub
8 changed files with 166 additions and 15 deletions

View File

@ -1,23 +1,12 @@
# Speech plugin
## Overview
The Speech plugin allows users to have text documents read out loud to them, by converting the selected text passage into speech.
Convert selected text into speech.
The plugin uses Yandex.Translate to recognize the language and the [ResponsiveVoice service](https://responsivevoice.org/) to read the text out loud. By default, it uses a female voice.
The plugin is pre-installed in ONLYOFFICE Enterprise Edition, Community Edition (Document Server + Community Server), ONLYOFFICE Integration Edition, ONLYOFFICE cloud service, and ONLYOFFICE Personal.
The Speech plugin is installed by default in cloud, [self-hosted](https://github.com/ONLYOFFICE/DocumentServer) and [desktop version](https://github.com/ONLYOFFICE/DesktopEditors) of ONLYOFFICE editors.
## How to use
1. Highlight the phrase you want to hear.
1. Highlight the phrase you want to here.
2. Open the Plugins tab and press Speech.
## Documentation
Plugins structure and installation https://api.onlyoffice.com/plugin/basic.
Plugins code and methods https://api.onlyoffice.com/docbuilder/basic.
## User feedback and support
To ask questions and share feedback, use Issues in this repository.

38
config.json Normal file
View File

@ -0,0 +1,38 @@
{
"name": "Speech",
"nameLocale": {
"ru": "Речь",
"fr": "Parole",
"es": "Habla",
"de": "Rede"
},
"guid": "asc.{D71C2EF0-F15B-47C7-80E9-86D671F9C595}",
"variations": [
{
"description": "Speech",
"descriptionLocale": {
"ru": "Речь",
"fr": "Parole",
"es": "Habla",
"de": "Rede"
},
"url": "index.html",
"icons": [ "icon.png", "icon@2x.png", "icon2.png", "icon2@2x.png" ],
"isViewer": true,
"EditorsSupport": [ "word" ],
"isVisual": false,
"isModal": false,
"isInsideMode": false,
"initDataType": "text",
"initData": "",
"isUpdateOleOnResize": false,
"buttons": []
}
]
}

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
icon2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
icon2@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
icon@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

12
index.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>speech</title>
<script type="text/javascript" src="https://onlyoffice.github.io/sdkjs-plugins/v1/plugins.js"></script>
<script src="https://code.responsivevoice.org/develop/responsivevoice.js"></script>
<script src="speech.js"></script>
</head>
<body style="width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;">
</body>
</html>

112
speech.js Normal file
View File

@ -0,0 +1,112 @@
(function(window, undefined)
{
var text_init = "";
window.Asc.plugin.init = function(text)
{
if ("" == text)
{
window.Asc.plugin.executeCommand("close", "");
return;
}
text_init = text;
function StartCallback()
{
}
function EndCallback()
{
window.Asc.plugin.button(-1);
}
function Run(lang)
{
var voicelist = responsiveVoice.getVoices();
var _data = [];
var _langs = responsiveVoice.responsivevoices;
var _map = {};
_map["en"] = ["gb"];
_map["ko"] = ["kr"];
for (var i = 0; i < _langs.length; i++)
{
if (_langs[i].flag == lang)
{
_data.push({index : i, gender : _langs[i].gender});
}
else if (_map[lang])
{
for (var k = 0; k < _map[lang].length; k++)
{
if (_langs[i].flag == _map[lang][k])
{
_data.push({index : i, gender : _langs[i].gender});
break;
}
}
}
}
var _index = 0;
if (_data.length > 0)
_index = _data[0].index;
for (var j = 0; j < _data.length; j++)
{
// family
if (_data[j].gender == "f")
{
_index = _data[j].index;
break;
}
}
responsiveVoice.speak(text_init, voicelist[_index].name, {onstart : StartCallback, onend : EndCallback});
}
responsiveVoice.AddEventListener("OnReady", function() {
setTimeout(function()
{
// detect language with yandex translate api
var xhr = new XMLHttpRequest();
var _url = "https://translate.yandex.net/api/v1.5/tr.json/detect?";
_url += "key=trnsl.1.1.20160604T115612Z.107ebb05a7757bcc.804e900f347ddfbeadd7ca5999bd5cb6ca32805b";
_url += "&text=";
_url += encodeURIComponent(text_init);
xhr.open('POST', _url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
try
{
var _obj = JSON.parse(this.responseText);
Run(_obj.lang);
}
catch (err)
{
Run("en");
}
}
else if (401 == this.readyState || 404 == this.readyState || 413 == this.readyState || 422 == this.readyState || 501 == this.readyState)
{
Run("en");
}
};
xhr.send(null);
}, 1);
});
};
window.Asc.plugin.button = function(id)
{
if (-1 == id)
responsiveVoice.cancel();
this.executeCommand("close", "");
};
})(window, undefined);