echogarden 1.4.4 → 1.6.0

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.
Files changed (240) hide show
  1. package/data/schemas/options.json +310 -25
  2. package/dist/alignment/DTWMfccSequenceAlignment.d.ts +1 -1
  3. package/dist/alignment/DTWMfccSequenceAlignment.js +5 -5
  4. package/dist/alignment/DTWSequenceAlignmentWindowed.js +1 -3
  5. package/dist/alignment/DTWSequenceAlignmentWindowed.js.map +1 -1
  6. package/dist/alignment/{TextAlignment.d.ts → SemanticTextAlignment.d.ts} +4 -2
  7. package/dist/alignment/SemanticTextAlignment.js +336 -0
  8. package/dist/alignment/SemanticTextAlignment.js.map +1 -0
  9. package/dist/alignment/SpeechAlignment.d.ts +4 -3
  10. package/dist/alignment/SpeechAlignment.js +130 -39
  11. package/dist/alignment/SpeechAlignment.js.map +1 -1
  12. package/dist/api/API.d.ts +7 -3
  13. package/dist/api/API.js +7 -2
  14. package/dist/api/API.js.map +1 -1
  15. package/dist/api/APIOptions.d.ts +4 -1
  16. package/dist/api/Alignment.d.ts +1 -1
  17. package/dist/api/Alignment.js +13 -5
  18. package/dist/api/Alignment.js.map +1 -1
  19. package/dist/api/LanguageDetectionCommon.d.ts +6 -0
  20. package/dist/api/LanguageDetectionCommon.js +2 -0
  21. package/dist/api/LanguageDetectionCommon.js.map +1 -0
  22. package/dist/api/Recognition.js.map +1 -1
  23. package/dist/api/{LanguageDetection.d.ts → SpeechLanguageDetection.d.ts} +1 -25
  24. package/dist/api/{LanguageDetection.js → SpeechLanguageDetection.js} +1 -68
  25. package/dist/api/SpeechLanguageDetection.js.map +1 -0
  26. package/dist/api/{Translation.js → SpeechTranslation.js} +3 -3
  27. package/dist/api/SpeechTranslation.js.map +1 -0
  28. package/dist/api/Synthesis.d.ts +0 -1
  29. package/dist/api/Synthesis.js +4 -4
  30. package/dist/api/TextLanguageDetection.d.ts +21 -0
  31. package/dist/api/TextLanguageDetection.js +67 -0
  32. package/dist/api/TextLanguageDetection.js.map +1 -0
  33. package/dist/api/TextTranslation.d.ts +25 -0
  34. package/dist/api/TextTranslation.js +101 -0
  35. package/dist/api/TextTranslation.js.map +1 -0
  36. package/dist/api/TimelineTranslationAlignment.d.ts +23 -0
  37. package/dist/api/TimelineTranslationAlignment.js +92 -0
  38. package/dist/api/TimelineTranslationAlignment.js.map +1 -0
  39. package/dist/api/TranscriptAndTranslationAlignment.d.ts +35 -0
  40. package/dist/api/TranscriptAndTranslationAlignment.js +78 -0
  41. package/dist/api/TranscriptAndTranslationAlignment.js.map +1 -0
  42. package/dist/api/TranslationAlignment.d.ts +4 -3
  43. package/dist/api/TranslationAlignment.js +9 -8
  44. package/dist/api/TranslationAlignment.js.map +1 -1
  45. package/dist/api/VoiceActivityDetection.js +16 -1
  46. package/dist/api/VoiceActivityDetection.js.map +1 -1
  47. package/dist/audio/AudioBufferConversion.d.ts +0 -1
  48. package/dist/audio/AudioPlayer.d.ts +0 -1
  49. package/dist/audio/AudioPlayer.js +62 -41
  50. package/dist/audio/AudioPlayer.js.map +1 -1
  51. package/dist/audio/AudioUtilities.d.ts +0 -1
  52. package/dist/cli/CLI.d.ts +28 -7
  53. package/dist/cli/CLI.js +265 -37
  54. package/dist/cli/CLI.js.map +1 -1
  55. package/dist/codecs/FFMpegTranscoder.d.ts +0 -1
  56. package/dist/codecs/FFMpegTranscoder.js +7 -0
  57. package/dist/codecs/FFMpegTranscoder.js.map +1 -1
  58. package/dist/codecs/TIMITCodec.d.ts +0 -1
  59. package/dist/codecs/WaveCodec.d.ts +0 -1
  60. package/dist/dsp/FFT.d.ts +1 -1
  61. package/dist/dsp/FFT.js +6 -0
  62. package/dist/dsp/FFT.js.map +1 -1
  63. package/dist/dsp/KWeightingFilter.js +1 -1
  64. package/dist/dsp/KWeightingFilter.js.map +1 -1
  65. package/dist/dsp/MelSpectogram.d.ts +3 -2
  66. package/dist/dsp/MelSpectogram.js +14 -8
  67. package/dist/dsp/MelSpectogram.js.map +1 -1
  68. package/dist/math/VectorMath.d.ts +9 -9
  69. package/dist/math/VectorMath.js +10 -10
  70. package/dist/math/VectorMath.js.map +1 -1
  71. package/dist/nlp/ChineseSegmentation.js +4 -4
  72. package/dist/nlp/ChineseSegmentation.js.map +1 -1
  73. package/dist/nlp/Segmentation.d.ts +2 -2
  74. package/dist/nlp/Segmentation.js +20 -13
  75. package/dist/nlp/Segmentation.js.map +1 -1
  76. package/dist/recognition/OpenAICloudSTT.d.ts +2 -1
  77. package/dist/recognition/OpenAICloudSTT.js +30 -19
  78. package/dist/recognition/OpenAICloudSTT.js.map +1 -1
  79. package/dist/recognition/SileroSTT.d.ts +0 -1
  80. package/dist/recognition/WhisperCppSTT.d.ts +3 -3
  81. package/dist/recognition/WhisperCppSTT.js +21 -9
  82. package/dist/recognition/WhisperCppSTT.js.map +1 -1
  83. package/dist/recognition/WhisperSTT.d.ts +9 -6
  84. package/dist/recognition/WhisperSTT.js +227 -46
  85. package/dist/recognition/WhisperSTT.js.map +1 -1
  86. package/dist/server/Client.d.ts +3 -4
  87. package/dist/server/Client.js.map +1 -1
  88. package/dist/server/Worker.d.ts +3 -3
  89. package/dist/server/Worker.js +3 -2
  90. package/dist/server/Worker.js.map +1 -1
  91. package/dist/source-separation/MDXNetSourceSeparation.d.ts +0 -1
  92. package/dist/source-separation/MDXNetSourceSeparation.js +1 -1
  93. package/dist/source-separation/MDXNetSourceSeparation.js.map +1 -1
  94. package/dist/speech-embeddings/WavToVec2BertFeatureEmbeddings.d.ts +12 -0
  95. package/dist/speech-embeddings/WavToVec2BertFeatureEmbeddings.js +68 -0
  96. package/dist/speech-embeddings/WavToVec2BertFeatureEmbeddings.js.map +1 -0
  97. package/dist/speech-language-detection/SileroLanguageDetection.d.ts +1 -2
  98. package/dist/speech-language-detection/SileroLanguageDetection.js +1 -1
  99. package/dist/speech-language-detection/SileroLanguageDetection.js.map +1 -1
  100. package/dist/subtitles/Subtitles.js +2 -2
  101. package/dist/subtitles/Subtitles.js.map +1 -1
  102. package/dist/synthesis/GoogleCloudTTS.d.ts +0 -1
  103. package/dist/synthesis/GoogleTranslateTTS.d.ts +0 -1
  104. package/dist/synthesis/GoogleTranslateTTS.js +6 -21
  105. package/dist/synthesis/GoogleTranslateTTS.js.map +1 -1
  106. package/dist/synthesis/StreamlabsPollyTTS.d.ts +0 -1
  107. package/dist/synthesis/VitsTTS.d.ts +0 -1
  108. package/dist/synthesis/VitsTTS.js +30 -0
  109. package/dist/synthesis/VitsTTS.js.map +1 -1
  110. package/dist/tests/Test.js +0 -31
  111. package/dist/tests/Test.js.map +1 -1
  112. package/dist/text-language-detection/FastTextLanguageDetection.d.ts +1 -1
  113. package/dist/text-language-detection/FastTextLanguageDetection.js.map +1 -1
  114. package/dist/text-language-detection/TinyLDLanguageDetection.d.ts +1 -1
  115. package/dist/text-language-detection/TinyLDLanguageDetection.js.map +1 -1
  116. package/dist/text-translation/DeepLTextTranslation.d.ts +2 -0
  117. package/dist/text-translation/DeepLTextTranslation.js +67 -0
  118. package/dist/text-translation/DeepLTextTranslation.js.map +1 -0
  119. package/dist/text-translation/GoogleTranslateTextTranslation.d.ts +10 -0
  120. package/dist/text-translation/GoogleTranslateTextTranslation.js +554 -0
  121. package/dist/text-translation/GoogleTranslateTextTranslation.js.map +1 -0
  122. package/dist/text-translation/NLLBTextTranslation.d.ts +2 -1
  123. package/dist/text-translation/NLLBTextTranslation.js +249 -19
  124. package/dist/text-translation/NLLBTextTranslation.js.map +1 -1
  125. package/dist/utilities/BinaryArrayConversion.d.ts +0 -1
  126. package/dist/utilities/BrowserRequestHeaders.d.ts +6 -0
  127. package/dist/utilities/BrowserRequestHeaders.js +52 -0
  128. package/dist/utilities/BrowserRequestHeaders.js.map +1 -0
  129. package/dist/utilities/BufferFileReadStream.d.ts +20 -0
  130. package/dist/utilities/BufferFileReadStream.js +81 -0
  131. package/dist/utilities/BufferFileReadStream.js.map +1 -0
  132. package/dist/utilities/DynamicUint8Array.d.ts +9 -0
  133. package/dist/utilities/DynamicUint8Array.js +31 -0
  134. package/dist/utilities/DynamicUint8Array.js.map +1 -0
  135. package/dist/utilities/FileSystem.d.ts +0 -2
  136. package/dist/utilities/Hashing.d.ts +3 -10
  137. package/dist/utilities/Hashing.js +10 -127
  138. package/dist/utilities/Hashing.js.map +1 -1
  139. package/dist/utilities/LEB128.d.ts +15 -5
  140. package/dist/utilities/LEB128.js +199 -119
  141. package/dist/utilities/LEB128.js.map +1 -1
  142. package/dist/utilities/LPVarInt.d.ts +11 -0
  143. package/dist/utilities/LPVarInt.js +187 -0
  144. package/dist/utilities/LPVarInt.js.map +1 -0
  145. package/dist/utilities/Locale.d.ts +1 -1
  146. package/dist/utilities/Locale.js +1 -1
  147. package/dist/utilities/OnnxUtilities.d.ts +1 -2
  148. package/dist/utilities/PVarInt.d.ts +4 -0
  149. package/dist/utilities/PVarInt.js +166 -0
  150. package/dist/utilities/PVarInt.js.map +1 -0
  151. package/dist/utilities/PackageManager.js +48 -25
  152. package/dist/utilities/PackageManager.js.map +1 -1
  153. package/dist/utilities/RandomGenerator.d.ts +3 -17
  154. package/dist/utilities/RandomGenerator.js +12 -81
  155. package/dist/utilities/RandomGenerator.js.map +1 -1
  156. package/dist/utilities/Timeline.d.ts +2 -0
  157. package/dist/utilities/Timeline.js +129 -20
  158. package/dist/utilities/Timeline.js.map +1 -1
  159. package/dist/utilities/Utilities.d.ts +1 -3
  160. package/dist/utilities/Utilities.js +30 -3
  161. package/dist/utilities/Utilities.js.map +1 -1
  162. package/dist/utilities/VarInt.d.ts +4 -0
  163. package/dist/utilities/VarInt.js +166 -0
  164. package/dist/utilities/VarInt.js.map +1 -0
  165. package/dist/utilities/VirtualFileReadStream.d.ts +20 -0
  166. package/dist/utilities/VirtualFileReadStream.js +79 -0
  167. package/dist/utilities/VirtualFileReadStream.js.map +1 -0
  168. package/dist/utilities/WebReader.js +7 -23
  169. package/dist/utilities/WebReader.js.map +1 -1
  170. package/dist/voice-activity-detection/SileroVAD.d.ts +0 -1
  171. package/docs/API.md +105 -3
  172. package/docs/CLI.md +51 -1
  173. package/docs/Engines.md +32 -3
  174. package/docs/Options.md +53 -12
  175. package/docs/Tasklist.md +1 -13
  176. package/package.json +20 -24
  177. package/src/alignment/DTWMfccSequenceAlignment.ts +5 -5
  178. package/src/alignment/DTWSequenceAlignmentWindowed.ts +1 -3
  179. package/src/alignment/SemanticTextAlignment.ts +467 -0
  180. package/src/alignment/SpeechAlignment.ts +214 -56
  181. package/src/api/API.ts +18 -2
  182. package/src/api/APIOptions.ts +14 -1
  183. package/src/api/Alignment.ts +31 -9
  184. package/src/api/LanguageDetectionCommon.ts +7 -0
  185. package/src/api/Recognition.ts +2 -0
  186. package/src/api/{LanguageDetection.ts → SpeechLanguageDetection.ts} +1 -119
  187. package/src/api/{Translation.ts → SpeechTranslation.ts} +2 -2
  188. package/src/api/Synthesis.ts +4 -4
  189. package/src/api/TextLanguageDetection.ts +116 -0
  190. package/src/api/TextTranslation.ts +177 -0
  191. package/src/api/TimelineTranslationAlignment.ts +162 -0
  192. package/src/api/TranscriptAndTranslationAlignment.ts +164 -0
  193. package/src/api/TranslationAlignment.ts +12 -10
  194. package/src/api/VoiceActivityDetection.ts +24 -3
  195. package/src/audio/AudioPlayer.ts +2 -0
  196. package/src/cli/CLI.ts +376 -40
  197. package/src/codecs/FFMpegTranscoder.ts +6 -0
  198. package/src/dsp/FFT.ts +8 -2
  199. package/src/dsp/KWeightingFilter.ts +1 -1
  200. package/src/dsp/MelSpectogram.ts +17 -8
  201. package/src/math/VectorMath.ts +15 -15
  202. package/src/nlp/ChineseSegmentation.ts +6 -4
  203. package/src/nlp/Segmentation.ts +18 -13
  204. package/src/recognition/OpenAICloudSTT.ts +47 -29
  205. package/src/recognition/WhisperCppSTT.ts +26 -11
  206. package/src/recognition/WhisperSTT.ts +364 -49
  207. package/src/server/Client.ts +3 -2
  208. package/src/server/Worker.ts +3 -2
  209. package/src/source-separation/MDXNetSourceSeparation.ts +1 -1
  210. package/src/speech-embeddings/WavToVec2BertFeatureEmbeddings.ts +107 -0
  211. package/src/speech-language-detection/SileroLanguageDetection.ts +2 -1
  212. package/src/subtitles/Subtitles.ts +2 -2
  213. package/src/synthesis/GoogleTranslateTTS.ts +7 -21
  214. package/src/synthesis/VitsTTS.ts +31 -3
  215. package/src/tests/Test.ts +1 -38
  216. package/src/text-language-detection/FastTextLanguageDetection.ts +1 -1
  217. package/src/text-language-detection/TinyLDLanguageDetection.ts +1 -1
  218. package/src/text-translation/DeepLTextTranslation.ts +88 -0
  219. package/src/text-translation/GoogleTranslateTextTranslation.ts +667 -0
  220. package/src/text-translation/NLLBTextTranslation.ts +261 -21
  221. package/src/typings/Fillers.d.ts +25 -2
  222. package/src/utilities/BrowserRequestHeaders.ts +59 -0
  223. package/src/utilities/DynamicUint8Array.ts +39 -0
  224. package/src/utilities/Hashing.ts +14 -167
  225. package/src/utilities/LEB128.ts +273 -148
  226. package/src/utilities/LPVarInt.ts +292 -0
  227. package/src/utilities/Locale.ts +1 -1
  228. package/src/utilities/OnnxUtilities.ts +1 -1
  229. package/src/utilities/PackageManager.ts +51 -30
  230. package/src/utilities/RandomGenerator.ts +12 -113
  231. package/src/utilities/Timeline.ts +162 -23
  232. package/src/utilities/Utilities.ts +40 -3
  233. package/src/utilities/VirtualFileReadStream.ts +109 -0
  234. package/src/utilities/WebReader.ts +9 -23
  235. package/dist/alignment/TextAlignment.js +0 -156
  236. package/dist/alignment/TextAlignment.js.map +0 -1
  237. package/dist/api/LanguageDetection.js.map +0 -1
  238. package/dist/api/Translation.js.map +0 -1
  239. package/src/alignment/TextAlignment.ts +0 -234
  240. /package/dist/api/{Translation.d.ts → SpeechTranslation.d.ts} +0 -0
@@ -0,0 +1,107 @@
1
+ import type * as Onnx from 'onnxruntime-node'
2
+ import { OnnxExecutionProvider, getOnnxSessionOptions } from '../utilities/OnnxUtilities.js';
3
+
4
+ import { RawAudio } from "../audio/AudioUtilities.js";
5
+ import { computeMelSpectogram } from "../dsp/MelSpectogram.js";
6
+ import { Logger } from '../utilities/Logger.js';
7
+ import { concatFloat32Arrays, splitFloat32Array } from '../utilities/Utilities.js';
8
+ import { applyEmphasis } from '../dsp/MFCC.js';
9
+
10
+ export function computeEmbeddings(audioSamples: RawAudio, modelFilePath: string, executionProviders: OnnxExecutionProvider[]) {
11
+ const wav2vecBert = new Wav2Vec2BertFeatureEmbeddings(
12
+ modelFilePath,
13
+ executionProviders,
14
+ )
15
+
16
+ const result = wav2vecBert.computeEmbeddings(audioSamples)
17
+
18
+ return result
19
+ }
20
+
21
+ export class Wav2Vec2BertFeatureEmbeddings {
22
+ session?: Onnx.InferenceSession
23
+
24
+ constructor(
25
+ public readonly modelFilePath: string,
26
+ public readonly executionProviders: OnnxExecutionProvider[]) {
27
+ }
28
+
29
+ async computeEmbeddings(rawAudio: RawAudio) {
30
+ const logger = new Logger()
31
+
32
+ rawAudio.audioChannels[0] = applyEmphasis(rawAudio.audioChannels[0], 0.97)
33
+
34
+ const { melSpectogram } = await computeMelSpectogram(
35
+ rawAudio,
36
+ 512,
37
+ 400,
38
+ 160,
39
+ 80,
40
+ 20,
41
+ 8000,
42
+ 'povey')
43
+
44
+ // Ensure even length
45
+ if (melSpectogram.length % 2 != 0) {
46
+ melSpectogram.push(new Float32Array(80))
47
+ }
48
+
49
+ // Normalize filterbanks
50
+ for (let filterbankIndex = 0; filterbankIndex < 80; filterbankIndex++) {
51
+ let sum = 0
52
+ let sumOfSquares = 0
53
+
54
+ for (let i = 0; i < melSpectogram.length; i++) {
55
+ const value = melSpectogram[i][filterbankIndex]
56
+
57
+ sum += value
58
+ sumOfSquares += value ** 2
59
+ }
60
+
61
+ const mean = sum / melSpectogram.length
62
+ const normalizationFactor = 1 / (Math.sqrt(sumOfSquares / melSpectogram.length) + 1e-40)
63
+
64
+ for (let i = 0; i < melSpectogram.length; i++) {
65
+ melSpectogram[i][filterbankIndex] -= mean
66
+ melSpectogram[i][filterbankIndex] *= normalizationFactor
67
+ }
68
+ }
69
+
70
+ // Flatten
71
+ const flattenedMelSpectogram = concatFloat32Arrays(melSpectogram)
72
+
73
+ // Initialize session
74
+ await this.initializeSessionIfNeeded()
75
+
76
+ const session = this.session!
77
+
78
+ const Onnx = await import('onnxruntime-node')
79
+
80
+ const inputTensor = new Onnx.Tensor('float32', flattenedMelSpectogram, [1, melSpectogram.length / 2, 80 * 2])
81
+
82
+ const attentionMask = new Int32Array(melSpectogram.length / 2).fill(1)
83
+ const attentionMaskTensor = new Onnx.Tensor('int32', attentionMask, [1, attentionMask.length])
84
+
85
+ // Run inference
86
+ const outputs = await session.run({ 'input_features': inputTensor, 'attention_mask': attentionMaskTensor })
87
+
88
+ // Return output
89
+ const lastHiddenStateData = outputs['last_hidden_state'].data as Float32Array
90
+
91
+ const outputEmbeddings = splitFloat32Array(lastHiddenStateData, outputs['last_hidden_state'].dims[2])
92
+
93
+ return outputEmbeddings
94
+ }
95
+
96
+ private async initializeSessionIfNeeded() {
97
+ if (this.session) {
98
+ return
99
+ }
100
+
101
+ const Onnx = await import('onnxruntime-node')
102
+
103
+ const onnxSessionOptions = getOnnxSessionOptions({ executionProviders: this.executionProviders })
104
+
105
+ this.session = await Onnx.InferenceSession.create(this.modelFilePath, onnxSessionOptions)
106
+ }
107
+ }
@@ -3,9 +3,10 @@ import { softmax } from '../math/VectorMath.js'
3
3
  import { Logger } from '../utilities/Logger.js'
4
4
  import { RawAudio } from '../audio/AudioUtilities.js'
5
5
  import { readAndParseJsonFile } from '../utilities/FileSystem.js'
6
- import { detectSpeechLanguageByParts, type LanguageDetectionResults } from '../api/LanguageDetection.js'
6
+ import { detectSpeechLanguageByParts } from '../api/SpeechLanguageDetection.js'
7
7
  import { languageCodeToName } from '../utilities/Locale.js'
8
8
  import { OnnxExecutionProvider, getOnnxSessionOptions } from '../utilities/OnnxUtilities.js'
9
+ import { LanguageDetectionResults } from '../api/LanguageDetectionCommon.js'
9
10
 
10
11
  export async function detectLanguage(
11
12
  rawAudio: RawAudio,
@@ -1,4 +1,4 @@
1
- import { convert as convertHtmlToText } from 'html-to-text'
1
+ import { htmlToText } from 'html-to-text'
2
2
 
3
3
  import { formatHMS, formatMS, secondsToHMS, secondsToMS, startsWithAnyOf } from '../utilities/Utilities.js'
4
4
  import { isWord, isWordOrSymbolWord } from '../nlp/Segmentation.js'
@@ -68,7 +68,7 @@ export function subtitlesToTimeline(subtitles: string, removeMarkup = true) {
68
68
 
69
69
  plainText = plainText.replaceAll(/<[^>]*>/g, '')
70
70
 
71
- plainText = convertHtmlToText(plainText, { wordwrap: false })
71
+ plainText = htmlToText(plainText, { wordwrap: false })
72
72
 
73
73
  plainText = plainText.replaceAll(/\s+/g, ' ').trim()
74
74
 
@@ -6,6 +6,7 @@ import { trimAudioEnd } from '../audio/AudioUtilities.js'
6
6
  import { Logger } from '../utilities/Logger.js'
7
7
  import { Timeline } from '../utilities/Timeline.js'
8
8
  import { getShortLanguageCode } from '../utilities/Locale.js'
9
+ import { getChromeOnWindowsHeaders } from '../utilities/BrowserRequestHeaders.js'
9
10
 
10
11
  const log = logToStderr
11
12
 
@@ -98,27 +99,11 @@ export async function synthesizeShortText(text: string, languageCode = 'en', tld
98
99
  },
99
100
 
100
101
  headers: {
101
- 'sec-ch-ua': `".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"`,
102
- 'x-same-domain': '1',
103
- 'dnt': '1',
104
- 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
105
- 'sec-ch-ua-mobile': '?0',
106
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
107
- 'sec-ch-ua-arch': 'x86',
108
- 'sec-ch-ua-full-version': '103.0.5060.114',
109
- 'sec-ch-ua-platform-version': '10.0.0',
110
- 'sec-ch-ua-full-version-list': `".Not/A)Brand";v="99.0.0.0", "Google Chrome";v="103.0.5060.114", "Chromium";v="103.0.5060.114"`,
111
- 'sec-ch-ua-bitness': '64',
112
- 'sec-ch-ua-model': '',
113
- 'sec-ch-ua-platform': 'Windows',
114
- 'accept': '*/*',
115
- 'origin': 'https://translate.google.com',
116
- 'sec-fetch-site': 'same-origin',
117
- 'sec-fetch-mode': 'cors',
118
- 'sec-fetch-dest': 'empty',
119
- 'referer': 'https://translate.google.com/',
120
- 'accept-encoding': 'gzip, deflate, br',
121
- 'accept-language': 'en-US,en;q=0.9',
102
+ ...getChromeOnWindowsHeaders({
103
+ origin: 'https://translate.google.${tld}',
104
+ referrer: `https://translate.google.${tld}/`
105
+ }),
106
+ 'Content-Type': 'application/x-www-form-urlencoded',
122
107
  },
123
108
 
124
109
  body: requestBody,
@@ -140,6 +125,7 @@ export async function synthesizeShortText(text: string, languageCode = 'en', tld
140
125
  }
141
126
 
142
127
  const resultMp3Stream = Buffer.concat(audioChunks)
128
+
143
129
  return resultMp3Stream
144
130
  }
145
131
 
@@ -252,6 +252,12 @@ export const voiceList: SynthesisVoice[] = [
252
252
  gender: 'male',
253
253
  },
254
254
 
255
+ {
256
+ name: 'cy_GB-gwryw_gogleddol-medium',
257
+ languages: ['cy-GB', 'cy'],
258
+ gender: 'male',
259
+ },
260
+
255
261
  {
256
262
  name: 'da_DK-nst_talesyntese-medium',
257
263
  languages: ['da-DK', 'da'],
@@ -375,7 +381,11 @@ export const voiceList: SynthesisVoice[] = [
375
381
  languages: ['en-GB', 'en'],
376
382
  gender: 'female',
377
383
  },
378
-
384
+ {
385
+ name: 'en_GB-cori-medium',
386
+ languages: ['en-GB', 'en'],
387
+ gender: 'female',
388
+ },
379
389
 
380
390
  {
381
391
  name: 'en_US-amy-low',
@@ -481,6 +491,21 @@ export const voiceList: SynthesisVoice[] = [
481
491
  languages: ['en-US', 'en'],
482
492
  gender: 'female',
483
493
  },
494
+ {
495
+ name: 'en_US-norman-medium',
496
+ languages: ['en-US', 'en'],
497
+ gender: 'male',
498
+ },
499
+ {
500
+ name: 'en_US-john-medium',
501
+ languages: ['en-US', 'en'],
502
+ gender: 'male',
503
+ },
504
+ {
505
+ name: 'en_US-bryce-medium',
506
+ languages: ['en-US', 'en'],
507
+ gender: 'male',
508
+ },
484
509
 
485
510
  {
486
511
  name: 'es_ES-carlfm-x_low',
@@ -531,7 +556,6 @@ export const voiceList: SynthesisVoice[] = [
531
556
  gender: 'male',
532
557
  },
533
558
 
534
-
535
559
  {
536
560
  name: 'fi_FI-harri-low',
537
561
  languages: ['fi-FI', 'fi'],
@@ -618,6 +642,11 @@ export const voiceList: SynthesisVoice[] = [
618
642
  languages: ['it-IT', 'it'],
619
643
  gender: 'male',
620
644
  },
645
+ {
646
+ name: 'it_IT-paola-medium',
647
+ languages: ['it-IT', 'it'],
648
+ gender: 'female',
649
+ },
621
650
 
622
651
  {
623
652
  name: 'ka_GE-natia-medium',
@@ -699,7 +728,6 @@ export const voiceList: SynthesisVoice[] = [
699
728
  gender: 'male',
700
729
  },
701
730
 
702
-
703
731
  {
704
732
  name: 'no_NO-talesyntese-medium',
705
733
  languages: ['no-NO', 'no'],
package/src/tests/Test.ts CHANGED
@@ -1,8 +1,5 @@
1
- import { getTokenRepetitionScore, logToStderr, setupProgramTerminationListeners, writeToStderr } from '../utilities/Utilities.js'
2
1
  import { makeTarballsForInstalledPackages } from '../utilities/TarballMaker.js'
3
- import { defaultEspeakOptions, listVoices, synthesize, testEspeakSynthesisWithPrePhonemizedInputs, testKirshenbaumPhonemization } from '../synthesis/EspeakTTS.js'
4
- import { getRawAudioDuration } from '../audio/AudioUtilities.js'
5
- import { alignText } from '../alignment/TextAlignment.js'
2
+ import { logToStderr, setupProgramTerminationListeners } from '../utilities/Utilities.js'
6
3
 
7
4
  const log = logToStderr
8
5
 
@@ -11,41 +8,7 @@ setupProgramTerminationListeners()
11
8
  //process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
12
9
  //process.env.http_proxy = 'http://localhost:8080'
13
10
 
14
- //const testText = `After a while, finding that nothing more happened, she decided on going into the garden at once; but, alas for poor Alice! when she got to the door, she found she had forgotten the little golden key, and when she went back to the table for it, she found she could not possibly reach it: she could see it quite plainly through the glass, and she tried her best to climb up one of the legs of the table, but it was too slippery; and when she had tired herself out with trying, the poor little thing sat down and cried.`
15
- //await testKirshenbaumPhonemization(testText)
16
-
17
- //getRepetitionScoreRelativeToFirstSubstring(['a', 'b', 'c', 'a', 'b', 'c'])
18
- //getRepetitionScoreRelativeToFirstSubstring(['a', 'b', 'a', 'd', 'a', 'b', 'a', 'd'])
19
- //getRepetitionScoreRelativeToFirstSubstring(['a', 'b', 'a', 'b', 'c', 'a', 'b', 'a', 'b'])
20
- //getRepetitionScoreRelativeToFirstSubstring(['a', 'a', 'a', 'b', 'a', 'a', 'a', 'b'])
21
- //getRepetitionScoreRelativeToFirstSubstring(['a', 'b', 'a', 'c', 'a', 'b', 'a', 'c', 'a'])
22
- //getRepetitionScoreRelativeToFirstSubstring(['a', 'a', 'a', 'b', 'b', 'a', 'a', 'a', 'b'])
23
-
24
11
  //await makeTarballsForInstalledPackages(true)
25
12
 
26
- /*
27
- const voices = await listVoices()
28
-
29
- for (const voice of voices) {
30
- const result = await synthesize('|', { ...defaultEspeakOptions, voice: voice.identifier })
31
-
32
- if (getRawAudioDuration(result.rawAudio) > 0.25) {
33
- log(voice.identifier)
34
- }
35
- }
36
- */
37
- /*
38
- await alignText(
39
- `
40
- Una mañana de invierno, un coche tirado por tres caballos pasó por en medio de Uzquiano y sin detenerse, siguió camino de Peña Cerrada. El coche había salido de Vitoria horas antes y llevaba tres viajeros, una muchachita vestida de blanco, talle alto, gabán, esclavina, gran sombrero Pamela, de moda por los años treinta y cinco al cuarenta, una criada vieja, de aspecto de dueña, enlutada, con peluca rojiza y toca blanca, y un hombre joven, alto, elegante, vestido de negro, con pantalón estrecho, entravillado y sombrero de copa.
41
- `,
42
- 'es',
43
- `
44
- One winter morning, a car drawn by three horses passed through the middle of Uzquiano and without stopping, continued on its way to Peña Cerrada. The car had left Vitoria hours before and was carrying three passengers, a little girl dressed in white, high-waisted, overcoat, cape, large Pamela hat, fashionable in the 1930s to 1940s, an old maid, with the appearance of a mistress, in mourning, with a reddish wig and a white cap, and a young, tall, elegant man, dressed in black, with narrow pants, a bow tie and a top hat.
45
- `,
46
- 'en',
47
- )
48
- */
49
-
50
13
  process.exit(0)
51
14
 
@@ -1,8 +1,8 @@
1
1
  import path from 'path'
2
- import type { LanguageDetectionResults } from '../api/LanguageDetection.js'
3
2
  import { languageCodeToName } from '../utilities/Locale.js'
4
3
  import { OpenPromise } from '../utilities/OpenPromise.js'
5
4
  import { resolveModuleMainPath, roundToDigits } from '../utilities/Utilities.js'
5
+ import { LanguageDetectionResults } from '../api/LanguageDetectionCommon.js'
6
6
 
7
7
  let fastTextLanguageDetectionModel: any
8
8
 
@@ -1,6 +1,6 @@
1
- import type { LanguageDetectionResults } from '../api/LanguageDetection.js'
2
1
  import { detectAll } from 'tinyld'
3
2
  import { languageCodeToName } from '../utilities/Locale.js'
3
+ import { LanguageDetectionResults } from '../api/LanguageDetectionCommon.js'
4
4
 
5
5
  export async function detectLanguage(text: string) {
6
6
  const tinyldResults = detectAll(text)
@@ -0,0 +1,88 @@
1
+ import { request } from "gaxios"
2
+ import { Logger } from "../utilities/Logger.js"
3
+ import { splitToSentences } from "../nlp/Segmentation.js"
4
+ import { TranslationPair } from "../api/TextTranslation.js"
5
+ import { getChromeOnWindowsHeaders } from "../utilities/BrowserRequestHeaders.js"
6
+
7
+ export async function translateText(text: string, sourceLanguage: string, targetLanguage: string): Promise<TranslationPair[]> {
8
+ const logger = new Logger()
9
+
10
+ logger.start(`Prepare request`)
11
+
12
+ const textSentences = splitToSentences(text, sourceLanguage)
13
+
14
+ const requestBodyObject = {
15
+ jsonrpc: '2.0',
16
+ method: 'LMT_handle_jobs',
17
+ params: {
18
+ jobs: [
19
+ {
20
+ kind: 'default',
21
+ sentences: [
22
+ {
23
+ text: textSentences[0],
24
+ id: 1,
25
+ prefix: '',
26
+ }
27
+ ],
28
+ raw_en_context_before: [],
29
+ raw_en_context_after: [],
30
+ preferred_num_beams: 4,
31
+ quality: 'fast',
32
+ }
33
+ ],
34
+
35
+ lang: {
36
+ target_lang: targetLanguage.toUpperCase(),
37
+
38
+ preference: {
39
+ weight: {},
40
+ default: 'default',
41
+ },
42
+
43
+ source_lang_computed: sourceLanguage.toUpperCase(),
44
+ },
45
+
46
+ priority: -1,
47
+
48
+ commonJobParams: {
49
+ mode: 'translate',
50
+ browserType: 1,
51
+ textType: 'plaintext',
52
+ },
53
+
54
+ timestamp: Date.now(),
55
+ },
56
+
57
+ id: 756456347,
58
+ }
59
+
60
+ const response = await request<any>({
61
+ method: 'POST',
62
+
63
+ url: `https://www2.deepl.com/jsonrpc`,
64
+
65
+ params: {
66
+ 'method': 'LMT_handle_jobs',
67
+ },
68
+
69
+ headers: {
70
+ ...getChromeOnWindowsHeaders({
71
+ origin: 'https://www.deepl.com',
72
+ referrer: `https://www.deepl.com/`
73
+ }),
74
+
75
+ 'Content-Type': 'application/json',
76
+ },
77
+
78
+ body: JSON.stringify(requestBodyObject),
79
+
80
+ responseType: 'json'
81
+ })
82
+
83
+ logger.start('Parse response')
84
+
85
+ logger.end()
86
+
87
+ return []
88
+ }