@magmamath/students-features 1.3.23-rc.6 → 1.3.23-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/features/translation/model/TranslationService.js +1 -1
- package/dist/commonjs/features/translation/model/TranslationService.js.map +1 -1
- package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionTranslation.model.js +20 -6
- package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionTranslation.model.js.map +1 -1
- package/dist/module/features/translation/model/TranslationService.js +1 -1
- package/dist/module/features/translation/model/TranslationService.js.map +1 -1
- package/dist/module/features/voice/playing/model/VoiceTranscriptionTranslation.model.js +20 -6
- package/dist/module/features/voice/playing/model/VoiceTranscriptionTranslation.model.js.map +1 -1
- package/dist/typescript/commonjs/features/translation/model/TranslationService.d.ts +1 -0
- package/dist/typescript/commonjs/features/translation/model/TranslationService.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscriptionTranslation.model.d.ts +1 -1
- package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscriptionTranslation.model.d.ts.map +1 -1
- package/dist/typescript/module/features/translation/model/TranslationService.d.ts +1 -0
- package/dist/typescript/module/features/translation/model/TranslationService.d.ts.map +1 -1
- package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionTranslation.model.d.ts +1 -1
- package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionTranslation.model.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/features/translation/model/TranslationService.ts +2 -1
- package/src/features/voice/playing/model/VoiceTranscriptionTranslation.model.ts +21 -7
|
@@ -55,7 +55,7 @@ class TranslationService {
|
|
|
55
55
|
if (this.cache.has(key)) return this.cache.get(key);
|
|
56
56
|
return text;
|
|
57
57
|
}
|
|
58
|
-
const source = this.sourceLanguage ?? undefined;
|
|
58
|
+
const source = config?.sourceLang ?? this.sourceLanguage ?? undefined;
|
|
59
59
|
const provider = this.getProvider(target);
|
|
60
60
|
const key = config?.cacheKey ?? this.createCacheKey(text, target, config?.cacheKeySuffix);
|
|
61
61
|
if (this.cache.has(key)) return this.cache.get(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_TranslationPreprocessor","require","TranslationService","preprocessor","TranslationKatexPreprocessor","cache","Map","providers","globalTargetLanguage","sourceLanguage","customCacheKeyFn","constructor","preserve","onError","setupPreservable","glossaryToPreserve","map","preserveWordsReplacers","replacers","getTargetLanguage","targetLang","target","Error","getProvider","provider","find","svc","isTargetSupported","createCacheKey","text","suffix","baseKey","Array","isArray","JSON","stringify","translate","config","isArrayInput","length","shouldSkipTranslation","key","cacheKey","cacheKeySuffix","has","get","source","undefined","translated","sanitized","replacements","sanitizeBatch","response","requestBatch","restoreBatch","sanitize","request","restore","set","bindTargetLanguage","store","callback","watch","t","value","setupTarget","bindSourceLanguage","bindCustomCacheKey","getCached","reset","clear","exports"],"sourceRoot":"../../../../../src","sources":["features/translation/model/TranslationService.ts"],"mappings":";;;;;;AACA,IAAAA,wBAAA,GAAAC,OAAA;
|
|
1
|
+
{"version":3,"names":["_TranslationPreprocessor","require","TranslationService","preprocessor","TranslationKatexPreprocessor","cache","Map","providers","globalTargetLanguage","sourceLanguage","customCacheKeyFn","constructor","preserve","onError","setupPreservable","glossaryToPreserve","map","preserveWordsReplacers","replacers","getTargetLanguage","targetLang","target","Error","getProvider","provider","find","svc","isTargetSupported","createCacheKey","text","suffix","baseKey","Array","isArray","JSON","stringify","translate","config","isArrayInput","length","shouldSkipTranslation","key","cacheKey","cacheKeySuffix","has","get","source","sourceLang","undefined","translated","sanitized","replacements","sanitizeBatch","response","requestBatch","restoreBatch","sanitize","request","restore","set","bindTargetLanguage","store","callback","watch","t","value","setupTarget","bindSourceLanguage","bindCustomCacheKey","getCached","reset","clear","exports"],"sourceRoot":"../../../../../src","sources":["features/translation/model/TranslationService.ts"],"mappings":";;;;;;AACA,IAAAA,wBAAA,GAAAC,OAAA;AAmBO,MAAMC,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,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEOG,kBAAkBA,CACvBP,KAAe,EACfC,QAAkF,EAC5E;IACND,KAAK,CAACE,KAAK,CAAEC,CAAC,IAAK;MACjB,IAAI,CAACtD,gBAAgB,GAAG,CAACmB,IAAuB,EAAER,MAAc,KAC9DyC,QAAQ,CAACE,CAAC,EAAE;QAAEnC,IAAI;QAAER;MAAO,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEOgD,SAASA,CAA8B5B,GAAW,EAAiB;IACxE,OAAO,IAAI,CAACpC,KAAK,CAACwC,GAAG,CAACJ,GAAG,CAAC;EAC5B;EAEO6B,KAAKA,CAAA,EAAG;IACb,IAAI,CAACjE,KAAK,CAACkE,KAAK,CAAC,CAAC;EACpB;AACF;AAACC,OAAA,CAAAtE,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.VoiceTranscriptionTranslationModel = void 0;
|
|
7
7
|
var _effector = require("effector");
|
|
8
|
+
var _TranslationService = require("../../../translation/model/TranslationService.js");
|
|
9
|
+
var _GoogleTranslationProvider = require("../../../translation/providers/google/GoogleTranslationProvider.js");
|
|
10
|
+
var _wordsToPreserve = require("../../../translation/preserve/wordsToPreserve.js");
|
|
8
11
|
class VoiceTranscriptionTranslationModel {
|
|
9
12
|
toggle = (0, _effector.createEvent)();
|
|
10
13
|
setActive = (0, _effector.createEvent)();
|
|
@@ -17,12 +20,11 @@ class VoiceTranscriptionTranslationModel {
|
|
|
17
20
|
}) => {
|
|
18
21
|
const item = this.collection.get(attemptNumber);
|
|
19
22
|
if (!item?.transcript) return null;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const text = await this.service.translate(item.transcript, {
|
|
24
|
+
targetLang: targetLanguage,
|
|
25
|
+
sourceLang: item.transcriptLanguage,
|
|
26
|
+
cacheKey: `voice::${attemptNumber}::${targetLanguage}`
|
|
24
27
|
});
|
|
25
|
-
const text = response.data.translations[0]?.translatedText;
|
|
26
28
|
if (!text) return null;
|
|
27
29
|
return {
|
|
28
30
|
attemptNumber,
|
|
@@ -38,7 +40,19 @@ class VoiceTranscriptionTranslationModel {
|
|
|
38
40
|
}).reset(this.reset, this.clearCache);
|
|
39
41
|
constructor(collection, api) {
|
|
40
42
|
this.collection = collection;
|
|
41
|
-
this.
|
|
43
|
+
this.service = new _TranslationService.TranslationService({
|
|
44
|
+
preserve: {
|
|
45
|
+
map: _wordsToPreserve.wordsToPreserve,
|
|
46
|
+
replacers: _wordsToPreserve.preservedWordsReplacers
|
|
47
|
+
},
|
|
48
|
+
providers: [new _GoogleTranslationProvider.GoogleTranslationProvider({
|
|
49
|
+
api: {
|
|
50
|
+
translateRequest: api.translateText
|
|
51
|
+
}
|
|
52
|
+
})]
|
|
53
|
+
});
|
|
54
|
+
this.clearCache.watch(() => this.service.reset());
|
|
55
|
+
this.reset.watch(() => this.service.reset());
|
|
42
56
|
}
|
|
43
57
|
getTranslation(attemptNumber) {
|
|
44
58
|
return this.$translations.getState()[attemptNumber];
|
package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionTranslation.model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_effector","require","VoiceTranscriptionTranslationModel","toggle","createEvent","setActive","clearCache","reset","$isActive","restore","on","state","translate","createEffect","attemptNumber","targetLanguage","item","collection","get","transcript","
|
|
1
|
+
{"version":3,"names":["_effector","require","_TranslationService","_GoogleTranslationProvider","_wordsToPreserve","VoiceTranscriptionTranslationModel","toggle","createEvent","setActive","clearCache","reset","$isActive","restore","on","state","translate","createEffect","attemptNumber","targetLanguage","item","collection","get","transcript","text","service","targetLang","sourceLang","transcriptLanguage","cacheKey","$translations","createStore","doneData","result","constructor","api","TranslationService","preserve","map","wordsToPreserve","replacers","preservedWordsReplacers","providers","GoogleTranslationProvider","translateRequest","translateText","watch","getTranslation","getState","exports"],"sourceRoot":"../../../../../../src","sources":["features/voice/playing/model/VoiceTranscriptionTranslation.model.ts"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAGA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,0BAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AAeO,MAAMI,kCAAkC,CAAC;EAI9BC,MAAM,GAAG,IAAAC,qBAAW,EAAC,CAAC;EACtBC,SAAS,GAAG,IAAAD,qBAAW,EAAU,CAAC;EAClCE,UAAU,GAAG,IAAAF,qBAAW,EAAC,CAAC;EAC1BG,KAAK,GAAG,IAAAH,qBAAW,EAAC,CAAC;EAErBI,SAAS,GAAG,IAAAC,iBAAO,EAAC,IAAI,CAACJ,SAAS,EAAE,KAAK,CAAC,CACvDK,EAAE,CAAC,IAAI,CAACP,MAAM,EAAGQ,KAAK,IAAK,CAACA,KAAK,CAAC,CAClCJ,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC;EAEJK,SAAS,GAAG,IAAAC,sBAAY,EACtC,OAAO;IAAEC,aAAa;IAAEC;EAAe,CAAC,KAAK;IAC3C,MAAMC,IAAI,GAAG,IAAI,CAACC,UAAU,CAACC,GAAG,CAACJ,aAAa,CAAC;IAC/C,IAAI,CAACE,IAAI,EAAEG,UAAU,EAAE,OAAO,IAAI;IAElC,MAAMC,IAAI,GAAG,MAAM,IAAI,CAACC,OAAO,CAACT,SAAS,CAACI,IAAI,CAACG,UAAU,EAAE;MACzDG,UAAU,EAAEP,cAAc;MAC1BQ,UAAU,EAAEP,IAAI,CAACQ,kBAAkB;MACnCC,QAAQ,EAAE,UAAUX,aAAa,KAAKC,cAAc;IACtD,CAAC,CAAC;IAEF,IAAI,CAACK,IAAI,EAAE,OAAO,IAAI;IAEtB,OAAO;MAAEN,aAAa;MAAEM;IAAK,CAAC;EAChC,CACF,CAAC;EAEeM,aAAa,GAAG,IAAAC,qBAAW,EAAyB,CAAC,CAAC,CAAC,CACpEjB,EAAE,CAAC,IAAI,CAACE,SAAS,CAACgB,QAAQ,EAAE,CAACjB,KAAK,EAAEkB,MAAM,KAAK;IAC9C,IAAI,CAACA,MAAM,EAAE,OAAOlB,KAAK;IACzB,OAAO;MAAE,GAAGA,KAAK;MAAE,CAACkB,MAAM,CAACf,aAAa,GAAGe,MAAM,CAACT;IAAK,CAAC;EAC1D,CAAC,CAAC,CACDb,KAAK,CAAC,IAAI,CAACA,KAAK,EAAE,IAAI,CAACD,UAAU,CAAC;EAErCwB,WAAWA,CAACb,UAAyC,EAAEc,GAAmB,EAAE;IAC1E,IAAI,CAACd,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACI,OAAO,GAAG,IAAIW,sCAAkB,CAAC;MACpCC,QAAQ,EAAE;QACRC,GAAG,EAAEC,gCAAe;QACpBC,SAAS,EAAEC;MACb,CAAC;MACDC,SAAS,EAAE,CAAC,IAAIC,oDAAyB,CAAC;QAAER,GAAG,EAAE;UAAES,gBAAgB,EAAET,GAAG,CAACU;QAAc;MAAE,CAAC,CAAC;IAC7F,CAAC,CAAC;IAEF,IAAI,CAACnC,UAAU,CAACoC,KAAK,CAAC,MAAM,IAAI,CAACrB,OAAO,CAACd,KAAK,CAAC,CAAC,CAAC;IACjD,IAAI,CAACA,KAAK,CAACmC,KAAK,CAAC,MAAM,IAAI,CAACrB,OAAO,CAACd,KAAK,CAAC,CAAC,CAAC;EAC9C;EAEOoC,cAAcA,CAAC7B,aAAqB,EAAsB;IAC/D,OAAO,IAAI,CAACY,aAAa,CAACkB,QAAQ,CAAC,CAAC,CAAC9B,aAAa,CAAC;EACrD;AACF;AAAC+B,OAAA,CAAA3C,kCAAA,GAAAA,kCAAA","ignoreList":[]}
|
|
@@ -51,7 +51,7 @@ export class TranslationService {
|
|
|
51
51
|
if (this.cache.has(key)) return this.cache.get(key);
|
|
52
52
|
return text;
|
|
53
53
|
}
|
|
54
|
-
const source = this.sourceLanguage ?? undefined;
|
|
54
|
+
const source = config?.sourceLang ?? this.sourceLanguage ?? undefined;
|
|
55
55
|
const provider = this.getProvider(target);
|
|
56
56
|
const key = config?.cacheKey ?? this.createCacheKey(text, target, config?.cacheKeySuffix);
|
|
57
57
|
if (this.cache.has(key)) return this.cache.get(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TranslationKatexPreprocessor","TranslationService","preprocessor","cache","Map","providers","globalTargetLanguage","sourceLanguage","customCacheKeyFn","constructor","preserve","onError","setupPreservable","glossaryToPreserve","map","preserveWordsReplacers","replacers","getTargetLanguage","targetLang","target","Error","getProvider","provider","find","svc","isTargetSupported","createCacheKey","text","suffix","baseKey","Array","isArray","JSON","stringify","translate","config","isArrayInput","length","shouldSkipTranslation","key","cacheKey","cacheKeySuffix","has","get","source","undefined","translated","sanitized","replacements","sanitizeBatch","response","requestBatch","restoreBatch","sanitize","request","restore","set","bindTargetLanguage","store","callback","watch","t","value","setupTarget","bindSourceLanguage","bindCustomCacheKey","getCached","reset","clear"],"sourceRoot":"../../../../../src","sources":["features/translation/model/TranslationService.ts"],"mappings":";;AACA,SAASA,4BAA4B,QAAQ,8BAA2B;
|
|
1
|
+
{"version":3,"names":["TranslationKatexPreprocessor","TranslationService","preprocessor","cache","Map","providers","globalTargetLanguage","sourceLanguage","customCacheKeyFn","constructor","preserve","onError","setupPreservable","glossaryToPreserve","map","preserveWordsReplacers","replacers","getTargetLanguage","targetLang","target","Error","getProvider","provider","find","svc","isTargetSupported","createCacheKey","text","suffix","baseKey","Array","isArray","JSON","stringify","translate","config","isArrayInput","length","shouldSkipTranslation","key","cacheKey","cacheKeySuffix","has","get","source","sourceLang","undefined","translated","sanitized","replacements","sanitizeBatch","response","requestBatch","restoreBatch","sanitize","request","restore","set","bindTargetLanguage","store","callback","watch","t","value","setupTarget","bindSourceLanguage","bindCustomCacheKey","getCached","reset","clear"],"sourceRoot":"../../../../../src","sources":["features/translation/model/TranslationService.ts"],"mappings":";;AACA,SA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,IAAK;MACrB,IAAI,CAACxD,cAAc,GAAGwD,KAAK;IAC7B,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEOG,kBAAkBA,CACvBP,KAAe,EACfC,QAAkF,EAC5E;IACND,KAAK,CAACE,KAAK,CAAEC,CAAC,IAAK;MACjB,IAAI,CAACtD,gBAAgB,GAAG,CAACmB,IAAuB,EAAER,MAAc,KAC9DyC,QAAQ,CAACE,CAAC,EAAE;QAAEnC,IAAI;QAAER;MAAO,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEOgD,SAASA,CAA8B5B,GAAW,EAAiB;IACxE,OAAO,IAAI,CAACpC,KAAK,CAACwC,GAAG,CAACJ,GAAG,CAAC;EAC5B;EAEO6B,KAAKA,CAAA,EAAG;IACb,IAAI,CAACjE,KAAK,CAACkE,KAAK,CAAC,CAAC;EACpB;AACF","ignoreList":[]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { createEffect, createEvent, createStore, restore } from 'effector';
|
|
4
|
+
import { TranslationService } from "../../../translation/model/TranslationService.js";
|
|
5
|
+
import { GoogleTranslationProvider } from "../../../translation/providers/google/GoogleTranslationProvider.js";
|
|
6
|
+
import { preservedWordsReplacers, wordsToPreserve } from "../../../translation/preserve/wordsToPreserve.js";
|
|
4
7
|
export class VoiceTranscriptionTranslationModel {
|
|
5
8
|
toggle = createEvent();
|
|
6
9
|
setActive = createEvent();
|
|
@@ -13,12 +16,11 @@ export class VoiceTranscriptionTranslationModel {
|
|
|
13
16
|
}) => {
|
|
14
17
|
const item = this.collection.get(attemptNumber);
|
|
15
18
|
if (!item?.transcript) return null;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
const text = await this.service.translate(item.transcript, {
|
|
20
|
+
targetLang: targetLanguage,
|
|
21
|
+
sourceLang: item.transcriptLanguage,
|
|
22
|
+
cacheKey: `voice::${attemptNumber}::${targetLanguage}`
|
|
20
23
|
});
|
|
21
|
-
const text = response.data.translations[0]?.translatedText;
|
|
22
24
|
if (!text) return null;
|
|
23
25
|
return {
|
|
24
26
|
attemptNumber,
|
|
@@ -34,7 +36,19 @@ export class VoiceTranscriptionTranslationModel {
|
|
|
34
36
|
}).reset(this.reset, this.clearCache);
|
|
35
37
|
constructor(collection, api) {
|
|
36
38
|
this.collection = collection;
|
|
37
|
-
this.
|
|
39
|
+
this.service = new TranslationService({
|
|
40
|
+
preserve: {
|
|
41
|
+
map: wordsToPreserve,
|
|
42
|
+
replacers: preservedWordsReplacers
|
|
43
|
+
},
|
|
44
|
+
providers: [new GoogleTranslationProvider({
|
|
45
|
+
api: {
|
|
46
|
+
translateRequest: api.translateText
|
|
47
|
+
}
|
|
48
|
+
})]
|
|
49
|
+
});
|
|
50
|
+
this.clearCache.watch(() => this.service.reset());
|
|
51
|
+
this.reset.watch(() => this.service.reset());
|
|
38
52
|
}
|
|
39
53
|
getTranslation(attemptNumber) {
|
|
40
54
|
return this.$translations.getState()[attemptNumber];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createEffect","createEvent","createStore","restore","VoiceTranscriptionTranslationModel","toggle","setActive","clearCache","reset","$isActive","on","state","translate","attemptNumber","targetLanguage","item","collection","get","transcript","
|
|
1
|
+
{"version":3,"names":["createEffect","createEvent","createStore","restore","TranslationService","GoogleTranslationProvider","preservedWordsReplacers","wordsToPreserve","VoiceTranscriptionTranslationModel","toggle","setActive","clearCache","reset","$isActive","on","state","translate","attemptNumber","targetLanguage","item","collection","get","transcript","text","service","targetLang","sourceLang","transcriptLanguage","cacheKey","$translations","doneData","result","constructor","api","preserve","map","replacers","providers","translateRequest","translateText","watch","getTranslation","getState"],"sourceRoot":"../../../../../../src","sources":["features/voice/playing/model/VoiceTranscriptionTranslation.model.ts"],"mappings":";;AAAA,SAASA,YAAY,EAAEC,WAAW,EAAEC,WAAW,EAAEC,OAAO,QAAQ,UAAU;AA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B,OAAO;MAAE,GAAGA,KAAK;MAAE,CAACgB,MAAM,CAACd,aAAa,GAAGc,MAAM,CAACR;IAAK,CAAC;EAC1D,CAAC,CAAC,CACDX,KAAK,CAAC,IAAI,CAACA,KAAK,EAAE,IAAI,CAACD,UAAU,CAAC;EAErCqB,WAAWA,CAACZ,UAAyC,EAAEa,GAAmB,EAAE;IAC1E,IAAI,CAACb,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACI,OAAO,GAAG,IAAIpB,kBAAkB,CAAC;MACpC8B,QAAQ,EAAE;QACRC,GAAG,EAAE5B,eAAe;QACpB6B,SAAS,EAAE9B;MACb,CAAC;MACD+B,SAAS,EAAE,CAAC,IAAIhC,yBAAyB,CAAC;QAAE4B,GAAG,EAAE;UAAEK,gBAAgB,EAAEL,GAAG,CAACM;QAAc;MAAE,CAAC,CAAC;IAC7F,CAAC,CAAC;IAEF,IAAI,CAAC5B,UAAU,CAAC6B,KAAK,CAAC,MAAM,IAAI,CAAChB,OAAO,CAACZ,KAAK,CAAC,CAAC,CAAC;IACjD,IAAI,CAACA,KAAK,CAAC4B,KAAK,CAAC,MAAM,IAAI,CAAChB,OAAO,CAACZ,KAAK,CAAC,CAAC,CAAC;EAC9C;EAEO6B,cAAcA,CAACxB,aAAqB,EAAsB;IAC/D,OAAO,IAAI,CAACY,aAAa,CAACa,QAAQ,CAAC,CAAC,CAACzB,aAAa,CAAC;EACrD;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TranslationService.d.ts","sourceRoot":"","sources":["../../../../../../src/features/translation/model/TranslationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAEhC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AAE1F,KAAK,uBAAuB,GAAG;IAC7B,SAAS,EAAE,mBAAmB,EAAE,CAAA;IAChC,QAAQ,CAAC,EAAE;QACT,GAAG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AAC,EAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,GACjF,IAAI;IASA,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIlE,KAAK;CAGb"}
|
|
1
|
+
{"version":3,"file":"TranslationService.d.ts","sourceRoot":"","sources":["../../../../../../src/features/translation/model/TranslationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAEhC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AAE1F,KAAK,uBAAuB,GAAG;IAC7B,SAAS,EAAE,mBAAmB,EAAE,CAAA;IAChC,QAAQ,CAAC,EAAE;QACT,GAAG,EAAE,gBAAgB,CAAA;QACrB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;KAC9B,CAAA;IACD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqC;IAClE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4B;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAA;IAExB,OAAO,CAAC,oBAAoB,CAAsB;IAClD,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,gBAAgB,CAAqE;gBAEjF,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,uBAAuB;IAYrE,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,cAAc;IAYf,SAAS,GAAU,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,SAC7C,CAAC,WACE,oBAAoB,KAC5B,OAAO,CAAC,CAAC,CAAC,CAgCZ;IAEM,kBAAkB,CAAC,CAAC,SAAS,MAAM,EACxC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,GAC9B,IAAI;IAUA,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI;IAQ3D,kBAAkB,CAAC,CAAC,SAAS,MAAM,EACxC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,GACjF,IAAI;IASA,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIlE,KAAK;CAGb"}
|
|
@@ -10,7 +10,7 @@ type TranslateResult = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare class VoiceTranscriptionTranslationModel {
|
|
12
12
|
private readonly collection;
|
|
13
|
-
private readonly
|
|
13
|
+
private readonly service;
|
|
14
14
|
readonly toggle: import("effector").EventCallable<void>;
|
|
15
15
|
readonly setActive: import("effector").EventCallable<boolean>;
|
|
16
16
|
readonly clearCache: import("effector").EventCallable<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceTranscriptionTranslation.model.d.ts","sourceRoot":"","sources":["../../../../../../../src/features/voice/playing/model/VoiceTranscriptionTranslation.model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"VoiceTranscriptionTranslation.model.d.ts","sourceRoot":"","sources":["../../../../../../../src/features/voice/playing/model/VoiceTranscriptionTranslation.model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAQ5C,KAAK,eAAe,GAAG;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,qBAAa,kCAAkC;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+B;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAE5C,SAAgB,MAAM,yCAAgB;IACtC,SAAgB,SAAS,4CAAyB;IAClD,SAAgB,UAAU,yCAAgB;IAC1C,SAAgB,KAAK,yCAAgB;IAErC,SAAgB,SAAS,4CAEL;IAEpB,SAAgB,SAAS,4EAexB;IAED,SAAgB,aAAa,2DAKQ;gBAEzB,UAAU,EAAE,6BAA6B,EAAE,GAAG,EAAE,cAAc;IAcnE,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAGjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TranslationService.d.ts","sourceRoot":"","sources":["../../../../../../src/features/translation/model/TranslationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAEhC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAA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,CAAC,CAAC,SAAS,MAAM,EACxC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,GACjF,IAAI;IASA,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIlE,KAAK;CAGb"}
|
|
1
|
+
{"version":3,"file":"TranslationService.d.ts","sourceRoot":"","sources":["../../../../../../src/features/translation/model/TranslationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAEhC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AAE1F,KAAK,uBAAuB,GAAG;IAC7B,SAAS,EAAE,mBAAmB,EAAE,CAAA;IAChC,QAAQ,CAAC,EAAE;QACT,GAAG,EAAE,gBAAgB,CAAA;QACrB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;KAC9B,CAAA;IACD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqC;IAClE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4B;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAA;IAExB,OAAO,CAAC,oBAAoB,CAAsB;IAClD,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,gBAAgB,CAAqE;gBAEjF,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,uBAAuB;IAYrE,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,cAAc;IAYf,SAAS,GAAU,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,SAC7C,CAAC,WACE,oBAAoB,KAC5B,OAAO,CAAC,CAAC,CAAC,CAgCZ;IAEM,kBAAkB,CAAC,CAAC,SAAS,MAAM,EACxC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,GAC9B,IAAI;IAUA,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI;IAQ3D,kBAAkB,CAAC,CAAC,SAAS,MAAM,EACxC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,GACjF,IAAI;IASA,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIlE,KAAK;CAGb"}
|
package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionTranslation.model.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ type TranslateResult = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare class VoiceTranscriptionTranslationModel {
|
|
12
12
|
private readonly collection;
|
|
13
|
-
private readonly
|
|
13
|
+
private readonly service;
|
|
14
14
|
readonly toggle: import("effector").EventCallable<void>;
|
|
15
15
|
readonly setActive: import("effector").EventCallable<boolean>;
|
|
16
16
|
readonly clearCache: import("effector").EventCallable<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceTranscriptionTranslation.model.d.ts","sourceRoot":"","sources":["../../../../../../../src/features/voice/playing/model/VoiceTranscriptionTranslation.model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"VoiceTranscriptionTranslation.model.d.ts","sourceRoot":"","sources":["../../../../../../../src/features/voice/playing/model/VoiceTranscriptionTranslation.model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAQ5C,KAAK,eAAe,GAAG;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,qBAAa,kCAAkC;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+B;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAE5C,SAAgB,MAAM,yCAAgB;IACtC,SAAgB,SAAS,4CAAyB;IAClD,SAAgB,UAAU,yCAAgB;IAC1C,SAAgB,KAAK,yCAAgB;IAErC,SAAgB,SAAS,4CAEL;IAEpB,SAAgB,SAAS,4EAexB;IAED,SAAgB,aAAa,2DAKQ;gBAEzB,UAAU,EAAE,6BAA6B,EAAE,GAAG,EAAE,cAAc;IAcnE,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAGjE"}
|
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ type TranslationServiceProps = {
|
|
|
13
13
|
|
|
14
14
|
export type TranslateConfigProps = {
|
|
15
15
|
targetLang?: string
|
|
16
|
+
sourceLang?: string
|
|
16
17
|
cacheKeySuffix?: string
|
|
17
18
|
cacheKey?: string
|
|
18
19
|
}
|
|
@@ -81,7 +82,7 @@ export class TranslationService {
|
|
|
81
82
|
return text
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
const source = this.sourceLanguage ?? undefined
|
|
85
|
+
const source = config?.sourceLang ?? this.sourceLanguage ?? undefined
|
|
85
86
|
const provider = this.getProvider(target)
|
|
86
87
|
const key = config?.cacheKey ?? this.createCacheKey(text, target, config?.cacheKeySuffix)
|
|
87
88
|
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { createEffect, createEvent, createStore, restore } from 'effector'
|
|
2
2
|
import { VoiceTranscriptionsCollection } from './VoiceTranscriptionsCollection'
|
|
3
3
|
import { VoicePlayerApi } from '../../types'
|
|
4
|
+
import { TranslationService } from '../../../translation/model/TranslationService'
|
|
5
|
+
import { GoogleTranslationProvider } from '../../../translation/providers/google/GoogleTranslationProvider'
|
|
6
|
+
import {
|
|
7
|
+
preservedWordsReplacers,
|
|
8
|
+
wordsToPreserve,
|
|
9
|
+
} from '../../../translation/preserve/wordsToPreserve'
|
|
4
10
|
|
|
5
11
|
type TranslateParams = {
|
|
6
12
|
attemptNumber: number
|
|
@@ -14,7 +20,7 @@ type TranslateResult = {
|
|
|
14
20
|
|
|
15
21
|
export class VoiceTranscriptionTranslationModel {
|
|
16
22
|
private readonly collection: VoiceTranscriptionsCollection
|
|
17
|
-
private readonly
|
|
23
|
+
private readonly service: TranslationService
|
|
18
24
|
|
|
19
25
|
public readonly toggle = createEvent()
|
|
20
26
|
public readonly setActive = createEvent<boolean>()
|
|
@@ -30,13 +36,12 @@ export class VoiceTranscriptionTranslationModel {
|
|
|
30
36
|
const item = this.collection.get(attemptNumber)
|
|
31
37
|
if (!item?.transcript) return null
|
|
32
38
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
const text = await this.service.translate(item.transcript, {
|
|
40
|
+
targetLang: targetLanguage,
|
|
41
|
+
sourceLang: item.transcriptLanguage,
|
|
42
|
+
cacheKey: `voice::${attemptNumber}::${targetLanguage}`,
|
|
37
43
|
})
|
|
38
44
|
|
|
39
|
-
const text = response.data.translations[0]?.translatedText
|
|
40
45
|
if (!text) return null
|
|
41
46
|
|
|
42
47
|
return { attemptNumber, text }
|
|
@@ -52,7 +57,16 @@ export class VoiceTranscriptionTranslationModel {
|
|
|
52
57
|
|
|
53
58
|
constructor(collection: VoiceTranscriptionsCollection, api: VoicePlayerApi) {
|
|
54
59
|
this.collection = collection
|
|
55
|
-
this.
|
|
60
|
+
this.service = new TranslationService({
|
|
61
|
+
preserve: {
|
|
62
|
+
map: wordsToPreserve,
|
|
63
|
+
replacers: preservedWordsReplacers,
|
|
64
|
+
},
|
|
65
|
+
providers: [new GoogleTranslationProvider({ api: { translateRequest: api.translateText } })],
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
this.clearCache.watch(() => this.service.reset())
|
|
69
|
+
this.reset.watch(() => this.service.reset())
|
|
56
70
|
}
|
|
57
71
|
|
|
58
72
|
public getTranslation(attemptNumber: number): string | undefined {
|