Use AudioSystem in Backend
This commit is contained in:
parent
e048a1efce
commit
cadcd72fad
@ -16,7 +16,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*global jpIsStringEntirelyKana, audioGetFromSources*/
|
/*global jpIsStringEntirelyKana*/
|
||||||
|
|
||||||
const audioUrlBuilders = new Map([
|
const audioUrlBuilders = new Map([
|
||||||
['jpod101', async (definition) => {
|
['jpod101', async (definition) => {
|
||||||
@ -154,7 +154,7 @@ function audioBuildFilename(definition) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function audioInject(definition, fields, sources, optionsContext) {
|
async function audioInject(definition, fields, sources, optionsContext, audioSystem) {
|
||||||
let usesAudio = false;
|
let usesAudio = false;
|
||||||
for (const fieldValue of Object.values(fields)) {
|
for (const fieldValue of Object.values(fields)) {
|
||||||
if (fieldValue.includes('{audio}')) {
|
if (fieldValue.includes('{audio}')) {
|
||||||
@ -171,12 +171,10 @@ async function audioInject(definition, fields, sources, optionsContext) {
|
|||||||
const expressions = definition.expressions;
|
const expressions = definition.expressions;
|
||||||
const audioSourceDefinition = Array.isArray(expressions) ? expressions[0] : definition;
|
const audioSourceDefinition = Array.isArray(expressions) ? expressions[0] : definition;
|
||||||
|
|
||||||
const {url} = await audioGetFromSources(audioSourceDefinition, sources, optionsContext, true);
|
const {uri} = await audioSystem.getExpressionAudio(audioSourceDefinition, sources, optionsContext, {tts: false});
|
||||||
if (url !== null) {
|
|
||||||
const filename = audioBuildFilename(audioSourceDefinition);
|
const filename = audioBuildFilename(audioSourceDefinition);
|
||||||
if (filename !== null) {
|
if (filename !== null) {
|
||||||
definition.audio = {url, filename};
|
definition.audio = {url: uri, filename};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -23,7 +23,7 @@ requestText, requestJson, optionsLoad
|
|||||||
dictConfigured, dictTermsSort, dictEnabledSet, dictNoteFormat
|
dictConfigured, dictTermsSort, dictEnabledSet, dictNoteFormat
|
||||||
audioGetUrl, audioInject
|
audioGetUrl, audioInject
|
||||||
jpConvertReading, jpDistributeFuriganaInflected, jpKatakanaToHiragana
|
jpConvertReading, jpDistributeFuriganaInflected, jpKatakanaToHiragana
|
||||||
Translator, AnkiConnect, AnkiNull, Mecab, BackendApiForwarder, JsonSchema, ClipboardMonitor*/
|
AudioSystem, Translator, AnkiConnect, AnkiNull, Mecab, BackendApiForwarder, JsonSchema, ClipboardMonitor*/
|
||||||
|
|
||||||
class Backend {
|
class Backend {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -34,6 +34,7 @@ class Backend {
|
|||||||
this.options = null;
|
this.options = null;
|
||||||
this.optionsSchema = null;
|
this.optionsSchema = null;
|
||||||
this.defaultAnkiFieldTemplates = null;
|
this.defaultAnkiFieldTemplates = null;
|
||||||
|
this.audioSystem = new AudioSystem();
|
||||||
this.optionsContext = {
|
this.optionsContext = {
|
||||||
depth: 0,
|
depth: 0,
|
||||||
url: window.location.href
|
url: window.location.href
|
||||||
@ -436,7 +437,8 @@ class Backend {
|
|||||||
definition,
|
definition,
|
||||||
options.anki.terms.fields,
|
options.anki.terms.fields,
|
||||||
options.audio.sources,
|
options.audio.sources,
|
||||||
optionsContext
|
optionsContext,
|
||||||
|
this.audioSystem
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user