echogarden 1.8.6 → 2.0.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 (299) hide show
  1. package/README.md +23 -18
  2. package/data/schemas/options.json +52 -47
  3. package/dist/alignment/DTWSequenceAlignment.d.ts +1 -1
  4. package/dist/alignment/DTWSequenceAlignment.js +5 -5
  5. package/dist/alignment/DTWSequenceAlignment.js.map +1 -1
  6. package/dist/alignment/SpeechAlignment.js +6 -6
  7. package/dist/alignment/SpeechAlignment.js.map +1 -1
  8. package/dist/api/Alignment.d.ts +1 -1
  9. package/dist/api/Alignment.js +49 -11
  10. package/dist/api/Alignment.js.map +1 -1
  11. package/dist/api/Denoising.d.ts +4 -2
  12. package/dist/api/Denoising.js +65 -13
  13. package/dist/api/Denoising.js.map +1 -1
  14. package/dist/api/SourceSeparation.js +9 -6
  15. package/dist/api/SourceSeparation.js.map +1 -1
  16. package/dist/api/SpeechLanguageDetection.js +4 -4
  17. package/dist/api/SpeechLanguageDetection.js.map +1 -1
  18. package/dist/api/Synthesis.d.ts +2 -2
  19. package/dist/api/Synthesis.js +10 -7
  20. package/dist/api/Synthesis.js.map +1 -1
  21. package/dist/api/VoiceActivityDetection.js +2 -2
  22. package/dist/api/VoiceActivityDetection.js.map +1 -1
  23. package/dist/audio/AudioBufferConversion.d.ts +2 -2
  24. package/dist/audio/AudioBufferConversion.js +77 -43
  25. package/dist/audio/AudioBufferConversion.js.map +1 -1
  26. package/dist/audio/AudioPlayer.d.ts +7 -5
  27. package/dist/audio/AudioPlayer.js +136 -50
  28. package/dist/audio/AudioPlayer.js.map +1 -1
  29. package/dist/audio/AudioUtilities.d.ts +4 -3
  30. package/dist/audio/AudioUtilities.js +30 -15
  31. package/dist/audio/AudioUtilities.js.map +1 -1
  32. package/dist/audio/SoxPath.js +3 -3
  33. package/dist/audio/SoxPath.js.map +1 -1
  34. package/dist/build-tools/MakeTarballsForInstalledPackages.js +3 -3
  35. package/dist/build-tools/MakeTarballsForInstalledPackages.js.map +1 -1
  36. package/dist/cli/CLI.js +30 -36
  37. package/dist/cli/CLI.js.map +1 -1
  38. package/dist/cli/CLIConfigFile.js +2 -2
  39. package/dist/cli/CLIConfigFile.js.map +1 -1
  40. package/dist/cli/CLIOptions.d.ts +2 -0
  41. package/dist/cli/CLIOptions.js +1 -1
  42. package/dist/cli/CLIOptions.js.map +1 -1
  43. package/dist/codecs/FFMpegTranscoder.d.ts +3 -3
  44. package/dist/codecs/FFMpegTranscoder.js +6 -6
  45. package/dist/codecs/FFMpegTranscoder.js.map +1 -1
  46. package/dist/codecs/TIMITCodec.d.ts +1 -1
  47. package/dist/codecs/TIMITCodec.js +4 -3
  48. package/dist/codecs/TIMITCodec.js.map +1 -1
  49. package/dist/codecs/WaveCodec.d.ts +3 -3
  50. package/dist/codecs/WaveCodec.js +37 -34
  51. package/dist/codecs/WaveCodec.js.map +1 -1
  52. package/dist/data-structures/DynamicTypedArray.d.ts +17 -0
  53. package/dist/data-structures/DynamicTypedArray.js +47 -0
  54. package/dist/data-structures/DynamicTypedArray.js.map +1 -0
  55. package/dist/data-structures/Queue.js.map +1 -0
  56. package/dist/data-structures/WindowedList.js.map +1 -0
  57. package/dist/denoising/NSNet2.d.ts +26 -0
  58. package/dist/denoising/NSNet2.js +128 -0
  59. package/dist/denoising/NSNet2.js.map +1 -0
  60. package/dist/denoising/RNNoise.js +3 -3
  61. package/dist/denoising/RNNoise.js.map +1 -1
  62. package/dist/dsp/FFT.d.ts +6 -1
  63. package/dist/dsp/FFT.js +17 -0
  64. package/dist/dsp/FFT.js.map +1 -1
  65. package/dist/encodings/Ascii.d.ts +10 -0
  66. package/dist/encodings/Ascii.js +41 -0
  67. package/dist/encodings/Ascii.js.map +1 -0
  68. package/dist/encodings/Base64.d.ts +5 -0
  69. package/dist/encodings/Base64.js +114 -0
  70. package/dist/encodings/Base64.js.map +1 -0
  71. package/dist/encodings/Hex.d.ts +3 -0
  72. package/dist/encodings/Hex.js +52 -0
  73. package/dist/encodings/Hex.js.map +1 -0
  74. package/dist/{utilities → encodings}/LEB128.d.ts +1 -1
  75. package/dist/{utilities → encodings}/LEB128.js +4 -4
  76. package/dist/encodings/LEB128.js.map +1 -0
  77. package/dist/{utilities → encodings}/LPVarInt.d.ts +1 -1
  78. package/dist/{utilities → encodings}/LPVarInt.js +6 -6
  79. package/dist/encodings/LPVarInt.js.map +1 -0
  80. package/dist/encodings/TextEncodingsCommon.d.ts +4 -0
  81. package/dist/encodings/TextEncodingsCommon.js +2 -0
  82. package/dist/encodings/TextEncodingsCommon.js.map +1 -0
  83. package/dist/encodings/Utf16.d.ts +10 -0
  84. package/dist/encodings/Utf16.js +36 -0
  85. package/dist/encodings/Utf16.js.map +1 -0
  86. package/dist/encodings/Utf32.d.ts +9 -0
  87. package/dist/encodings/Utf32.js +44 -0
  88. package/dist/encodings/Utf32.js.map +1 -0
  89. package/dist/encodings/Utf8.d.ts +10 -0
  90. package/dist/encodings/Utf8.js +97 -0
  91. package/dist/encodings/Utf8.js.map +1 -0
  92. package/dist/math/MedianFilter.js.map +1 -1
  93. package/dist/nlp/JapaneseSegmentation.js +2 -2
  94. package/dist/nlp/JapaneseSegmentation.js.map +1 -1
  95. package/dist/recognition/GoogleCloudSTT.js +2 -1
  96. package/dist/recognition/GoogleCloudSTT.js.map +1 -1
  97. package/dist/recognition/SileroSTT.js +3 -3
  98. package/dist/recognition/SileroSTT.js.map +1 -1
  99. package/dist/recognition/VoskSTT.js +3 -3
  100. package/dist/recognition/VoskSTT.js.map +1 -1
  101. package/dist/recognition/WhisperCppSTT.js +4 -5
  102. package/dist/recognition/WhisperCppSTT.js.map +1 -1
  103. package/dist/recognition/WhisperSTT.js +8 -7
  104. package/dist/recognition/WhisperSTT.js.map +1 -1
  105. package/dist/server/Client.d.ts +1 -1
  106. package/dist/server/Client.js +2 -1
  107. package/dist/server/Client.js.map +1 -1
  108. package/dist/server/Server.js +5 -4
  109. package/dist/server/Server.js.map +1 -1
  110. package/dist/server/Worker.js +1 -1
  111. package/dist/server/Worker.js.map +1 -1
  112. package/dist/source-separation/MDXNetSourceSeparation.js +1 -1
  113. package/dist/source-separation/MDXNetSourceSeparation.js.map +1 -1
  114. package/dist/speech-search/DTWSpeechSearch.d.ts +1 -1
  115. package/dist/speech-search/DTWSpeechSearch.js +25 -6
  116. package/dist/speech-search/DTWSpeechSearch.js.map +1 -1
  117. package/dist/subtitles/Subtitles.js +2 -2
  118. package/dist/subtitles/Subtitles.js.map +1 -1
  119. package/dist/synthesis/AzureCognitiveServicesTTS.js +17 -18
  120. package/dist/synthesis/AzureCognitiveServicesTTS.js.map +1 -1
  121. package/dist/synthesis/CoquiServerTTS.js +1 -1
  122. package/dist/synthesis/CoquiServerTTS.js.map +1 -1
  123. package/dist/synthesis/ElevenlabsTTS.js +1 -1
  124. package/dist/synthesis/ElevenlabsTTS.js.map +1 -1
  125. package/dist/synthesis/EspeakTTS.d.ts +0 -1
  126. package/dist/synthesis/EspeakTTS.js +0 -9
  127. package/dist/synthesis/EspeakTTS.js.map +1 -1
  128. package/dist/synthesis/FliteTTS.js +7 -8
  129. package/dist/synthesis/FliteTTS.js.map +1 -1
  130. package/dist/synthesis/GoogleCloudTTS.d.ts +1 -1
  131. package/dist/synthesis/GoogleCloudTTS.js +2 -1
  132. package/dist/synthesis/GoogleCloudTTS.js.map +1 -1
  133. package/dist/synthesis/GoogleTranslateTTS.d.ts +1 -1
  134. package/dist/synthesis/GoogleTranslateTTS.js +4 -3
  135. package/dist/synthesis/GoogleTranslateTTS.js.map +1 -1
  136. package/dist/synthesis/MicrosoftEdgeTTS.js +32 -7
  137. package/dist/synthesis/MicrosoftEdgeTTS.js.map +1 -1
  138. package/dist/synthesis/SapiTTS.js +1 -1
  139. package/dist/synthesis/SapiTTS.js.map +1 -1
  140. package/dist/synthesis/StreamlabsPollyTTS.d.ts +1 -1
  141. package/dist/synthesis/StreamlabsPollyTTS.js +1 -1
  142. package/dist/synthesis/StreamlabsPollyTTS.js.map +1 -1
  143. package/dist/synthesis/SvoxPicoTTS.js +6 -5
  144. package/dist/synthesis/SvoxPicoTTS.js.map +1 -1
  145. package/dist/synthesis/VitsTTS.js +2 -2
  146. package/dist/synthesis/VitsTTS.js.map +1 -1
  147. package/dist/tests/Test.js +0 -25
  148. package/dist/tests/Test.js.map +1 -1
  149. package/dist/text-language-detection/FastTextLanguageDetection.js +2 -2
  150. package/dist/text-language-detection/FastTextLanguageDetection.js.map +1 -1
  151. package/dist/typings/TypedArray.d.ts +4 -0
  152. package/dist/typings/TypedArray.js +2 -0
  153. package/dist/typings/TypedArray.js.map +1 -0
  154. package/dist/utilities/BinaryArrayConversion.d.ts +12 -22
  155. package/dist/utilities/BinaryArrayConversion.js +40 -90
  156. package/dist/utilities/BinaryArrayConversion.js.map +1 -1
  157. package/dist/utilities/BinaryUtilities.d.ts +13 -0
  158. package/dist/utilities/BinaryUtilities.js +113 -0
  159. package/dist/utilities/BinaryUtilities.js.map +1 -0
  160. package/dist/utilities/Compression.js +7 -6
  161. package/dist/utilities/Compression.js.map +1 -1
  162. package/dist/utilities/FileDownloader.js +26 -47
  163. package/dist/utilities/FileDownloader.js.map +1 -1
  164. package/dist/utilities/FileReader.d.ts +14 -0
  165. package/dist/utilities/FileReader.js +71 -0
  166. package/dist/utilities/FileReader.js.map +1 -0
  167. package/dist/utilities/FileSystem.d.ts +19 -17
  168. package/dist/utilities/FileSystem.js +170 -106
  169. package/dist/utilities/FileSystem.js.map +1 -1
  170. package/dist/utilities/FileWriter.d.ts +12 -0
  171. package/dist/utilities/FileWriter.js +60 -0
  172. package/dist/utilities/FileWriter.js.map +1 -0
  173. package/dist/utilities/NpmUtilities.d.ts +1 -0
  174. package/dist/utilities/NpmUtilities.js +14 -0
  175. package/dist/utilities/NpmUtilities.js.map +1 -0
  176. package/dist/utilities/PackageManager.js +7 -5
  177. package/dist/utilities/PackageManager.js.map +1 -1
  178. package/dist/utilities/PathUtilities.d.ts +8 -0
  179. package/dist/utilities/PathUtilities.js +28 -7
  180. package/dist/utilities/PathUtilities.js.map +1 -1
  181. package/dist/utilities/SignalChannel.d.ts +3 -1
  182. package/dist/utilities/SignalChannel.js +9 -5
  183. package/dist/utilities/SignalChannel.js.map +1 -1
  184. package/dist/utilities/StringBuilder.d.ts +10 -0
  185. package/dist/utilities/StringBuilder.js +39 -0
  186. package/dist/utilities/StringBuilder.js.map +1 -0
  187. package/dist/utilities/StringUtilities.js.map +1 -1
  188. package/dist/utilities/TarballMaker.js +6 -7
  189. package/dist/utilities/TarballMaker.js.map +1 -1
  190. package/dist/utilities/Timer.js +2 -2
  191. package/dist/utilities/Timer.js.map +1 -1
  192. package/dist/utilities/Utilities.d.ts +11 -4
  193. package/dist/utilities/Utilities.js +70 -18
  194. package/dist/utilities/Utilities.js.map +1 -1
  195. package/dist/utilities/VirtualFileReadStream.d.ts +3 -3
  196. package/dist/utilities/VirtualFileReadStream.js.map +1 -1
  197. package/dist/utilities/WasmMemoryManager.d.ts +5 -2
  198. package/dist/utilities/WasmMemoryManager.js +15 -3
  199. package/dist/utilities/WasmMemoryManager.js.map +1 -1
  200. package/docs/API.md +1 -1
  201. package/docs/Licenses.md +3 -0
  202. package/docs/Options.md +9 -3
  203. package/docs/Tasklist.md +0 -1
  204. package/docs/Technical.md +2 -2
  205. package/package.json +20 -22
  206. package/src/alignment/DTWSequenceAlignment.ts +5 -5
  207. package/src/alignment/SpeechAlignment.ts +6 -6
  208. package/src/api/Alignment.ts +65 -12
  209. package/src/api/Denoising.ts +97 -17
  210. package/src/api/SourceSeparation.ts +11 -8
  211. package/src/api/SpeechLanguageDetection.ts +4 -4
  212. package/src/api/Synthesis.ts +15 -11
  213. package/src/api/VoiceActivityDetection.ts +2 -2
  214. package/src/audio/AudioBufferConversion.ts +84 -45
  215. package/src/audio/AudioPlayer.ts +156 -54
  216. package/src/audio/AudioUtilities.ts +38 -22
  217. package/src/audio/SoxPath.ts +3 -3
  218. package/src/build-tools/MakeTarballsForInstalledPackages.ts +3 -3
  219. package/src/cli/CLI.ts +30 -36
  220. package/src/cli/CLIConfigFile.ts +2 -2
  221. package/src/cli/CLIOptions.ts +4 -1
  222. package/src/codecs/FFMpegTranscoder.ts +11 -11
  223. package/src/codecs/TIMITCodec.ts +5 -4
  224. package/src/codecs/WaveCodec.ts +42 -39
  225. package/src/data-structures/DynamicTypedArray.ts +64 -0
  226. package/src/denoising/NSNet2.ts +182 -0
  227. package/src/denoising/RNNoise.ts +3 -3
  228. package/src/dsp/FFT.ts +21 -1
  229. package/src/encodings/Ascii.ts +60 -0
  230. package/src/encodings/Base64.ts +157 -0
  231. package/src/encodings/Hex.ts +67 -0
  232. package/src/{utilities → encodings}/LEB128.ts +4 -4
  233. package/src/{utilities → encodings}/LPVarInt.ts +6 -6
  234. package/src/encodings/TextEncodingsCommon.ts +4 -0
  235. package/src/encodings/Utf16.ts +52 -0
  236. package/src/encodings/Utf32.ts +62 -0
  237. package/src/encodings/Utf8.ts +117 -0
  238. package/src/math/MedianFilter.ts +0 -2
  239. package/src/nlp/JapaneseSegmentation.ts +2 -2
  240. package/src/recognition/GoogleCloudSTT.ts +2 -1
  241. package/src/recognition/SileroSTT.ts +3 -3
  242. package/src/recognition/VoskSTT.ts +3 -3
  243. package/src/recognition/WhisperCppSTT.ts +4 -5
  244. package/src/recognition/WhisperSTT.ts +8 -7
  245. package/src/server/Client.ts +4 -3
  246. package/src/server/Server.ts +6 -5
  247. package/src/server/Worker.ts +1 -1
  248. package/src/source-separation/MDXNetSourceSeparation.ts +1 -1
  249. package/src/speech-search/DTWSpeechSearch.ts +36 -7
  250. package/src/subtitles/Subtitles.ts +3 -3
  251. package/src/synthesis/AzureCognitiveServicesTTS.ts +18 -15
  252. package/src/synthesis/CoquiServerTTS.ts +2 -2
  253. package/src/synthesis/ElevenlabsTTS.ts +1 -1
  254. package/src/synthesis/EspeakTTS.ts +0 -15
  255. package/src/synthesis/FliteTTS.ts +7 -8
  256. package/src/synthesis/GoogleCloudTTS.ts +3 -2
  257. package/src/synthesis/GoogleTranslateTTS.ts +5 -4
  258. package/src/synthesis/MicrosoftEdgeTTS.ts +47 -15
  259. package/src/synthesis/SapiTTS.ts +1 -1
  260. package/src/synthesis/StreamlabsPollyTTS.ts +1 -1
  261. package/src/synthesis/SvoxPicoTTS.ts +8 -7
  262. package/src/synthesis/VitsTTS.ts +2 -2
  263. package/src/tests/Test.ts +0 -30
  264. package/src/text-language-detection/FastTextLanguageDetection.ts +2 -2
  265. package/src/typings/Fillers.d.ts +2 -4
  266. package/src/typings/TypedArray.ts +5 -0
  267. package/src/utilities/BinaryArrayConversion.ts +51 -125
  268. package/src/utilities/BinaryUtilities.ts +138 -0
  269. package/src/utilities/Compression.ts +7 -6
  270. package/src/utilities/FileDownloader.ts +27 -52
  271. package/src/utilities/FileReader.ts +89 -0
  272. package/src/utilities/FileSystem.ts +215 -116
  273. package/src/utilities/FileWriter.ts +72 -0
  274. package/src/utilities/NpmUtilities.ts +23 -0
  275. package/src/utilities/PackageManager.ts +8 -5
  276. package/src/utilities/PathUtilities.ts +36 -7
  277. package/src/utilities/SignalChannel.ts +14 -7
  278. package/src/utilities/StringBuilder.ts +45 -0
  279. package/src/utilities/StringUtilities.ts +2 -0
  280. package/src/utilities/TarballMaker.ts +6 -7
  281. package/src/utilities/Timer.ts +4 -2
  282. package/src/utilities/Utilities.ts +80 -23
  283. package/src/utilities/VirtualFileReadStream.ts +5 -5
  284. package/src/utilities/WasmMemoryManager.ts +21 -5
  285. package/tsconfig.json +96 -0
  286. package/dist/utilities/DynamicUint8Array.d.ts +0 -9
  287. package/dist/utilities/DynamicUint8Array.js +0 -31
  288. package/dist/utilities/DynamicUint8Array.js.map +0 -1
  289. package/dist/utilities/LEB128.js.map +0 -1
  290. package/dist/utilities/LPVarInt.js.map +0 -1
  291. package/dist/utilities/Queue.js.map +0 -1
  292. package/dist/utilities/WindowedList.js.map +0 -1
  293. package/src/utilities/DynamicUint8Array.ts +0 -39
  294. /package/dist/{utilities → data-structures}/Queue.d.ts +0 -0
  295. /package/dist/{utilities → data-structures}/Queue.js +0 -0
  296. /package/dist/{utilities → data-structures}/WindowedList.d.ts +0 -0
  297. /package/dist/{utilities → data-structures}/WindowedList.js +0 -0
  298. /package/src/{utilities → data-structures}/Queue.ts +0 -0
  299. /package/src/{utilities → data-structures}/WindowedList.ts +0 -0
@@ -2,10 +2,9 @@ import { SynthesisVoice } from '../api/API.js'
2
2
  import { decodeWaveToRawAudio } from '../audio/AudioUtilities.js'
3
3
  import { Logger } from '../utilities/Logger.js'
4
4
  import { getRandomHexString, logToStderr, resolveModuleMainPath } from '../utilities/Utilities.js'
5
- import { readFile, open, close, remove, ensureDir } from '../utilities/FileSystem.js'
6
- import path from 'node:path'
5
+ import { open, close, remove, ensureDir, readFileAsBinary, readFileAsUtf8 } from '../utilities/FileSystem.js'
7
6
  import { escape } from 'html-escaper'
8
- import { getAppTempDir } from '../utilities/PathUtilities.js'
7
+ import { getAppTempDir, joinPath } from '../utilities/PathUtilities.js'
9
8
 
10
9
  const log = logToStderr
11
10
 
@@ -25,8 +24,8 @@ export async function synthesize(text: string, voice: FliteVoiceName, voiceDir:
25
24
  const tempDir = getAppTempDir('flite')
26
25
  await ensureDir(tempDir)
27
26
 
28
- const tempAudioFilePath = path.join(tempDir, outFileName)
29
- const tempStdOutFilePath = path.join(tempDir, stdOutFileName)
27
+ const tempAudioFilePath = joinPath(tempDir, outFileName)
28
+ const tempStdOutFilePath = joinPath(tempDir, stdOutFileName)
30
29
 
31
30
  const stdOutFileFd = await open(tempStdOutFilePath, 'w+')
32
31
 
@@ -100,8 +99,8 @@ export async function synthesize(text: string, voice: FliteVoiceName, voiceDir:
100
99
  throw new Error(`Flite failed with exit code ${exitCode}`)
101
100
  }
102
101
 
103
- const waveData = await readFile(tempAudioFilePath)
104
- const stdOutString = await readFile(tempStdOutFilePath, 'utf8')
102
+ const waveData = await readFileAsBinary(tempAudioFilePath)
103
+ const stdOutString = await readFileAsUtf8(tempStdOutFilePath)
105
104
 
106
105
  await cleanup()
107
106
 
@@ -118,7 +117,7 @@ async function getModuleObject() {
118
117
  if (!fliteModuleObject) {
119
118
  const fliteWasiPath = await resolveModuleMainPath('@echogarden/flite-wasi')
120
119
 
121
- fliteModuleObject = await WebAssembly.compile(await readFile(fliteWasiPath))
120
+ fliteModuleObject = await WebAssembly.compile(await readFileAsBinary(fliteWasiPath))
122
121
  }
123
122
 
124
123
  return fliteModuleObject
@@ -1,6 +1,7 @@
1
1
  import { request } from 'gaxios'
2
2
  import { Logger } from '../utilities/Logger.js'
3
3
  import { logToStderr } from '../utilities/Utilities.js'
4
+ import { decodeBase64 } from '../encodings/Base64.js'
4
5
 
5
6
  const log = logToStderr
6
7
 
@@ -15,7 +16,7 @@ export async function synthesize(
15
16
  ssml = false,
16
17
  audioEncoding: AudioEncoding = 'MP3_64_KBPS',
17
18
  sampleRate = 24000) {
18
-
19
+
19
20
  const logger = new Logger()
20
21
  logger.start('Request synthesis from Google Cloud')
21
22
 
@@ -75,7 +76,7 @@ export async function synthesize(
75
76
  }
76
77
 
77
78
  function parseResponseBody(responseBody: any) {
78
- const audioData = Buffer.from(responseBody.audioContent, 'base64')
79
+ const audioData = decodeBase64(responseBody.audioContent)
79
80
  const timepoints: timePoint[] = responseBody.timepoints
80
81
 
81
82
  return { audioData, timepoints }
@@ -1,12 +1,13 @@
1
1
  import { request } from 'gaxios'
2
2
  import { Phrase, splitToFragments } from '../nlp/Segmentation.js'
3
- import { concatFloat32Arrays, logToStderr } from '../utilities/Utilities.js'
3
+ import { concatFloat32Arrays, concatUint8Arrays, logToStderr } from '../utilities/Utilities.js'
4
4
  import * as FFMpegTranscoder from '../codecs/FFMpegTranscoder.js'
5
5
  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
9
  import { getChromeOnWindowsHeaders } from '../utilities/BrowserRequestHeaders.js'
10
+ import { decodeBase64 } from '../encodings/Base64.js'
10
11
 
11
12
  const log = logToStderr
12
13
 
@@ -113,18 +114,18 @@ export async function synthesizeShortText(text: string, languageCode = 'en', tld
113
114
 
114
115
  //log(response.data)
115
116
 
116
- const audioChunks: Buffer[] = []
117
+ const audioChunks: Uint8Array[] = []
117
118
 
118
119
  for (const line of response.data.split(/\r?\n/)) {
119
120
  const match = line.match(/"jQ1olc","\[\\"(.*)\\"]/)
120
121
 
121
122
  if (match != null) {
122
123
  const base64AudioChunk = match[1]
123
- audioChunks.push(Buffer.from(base64AudioChunk, 'base64'))
124
+ audioChunks.push(decodeBase64(base64AudioChunk))
124
125
  }
125
126
  }
126
127
 
127
- const resultMp3Stream = Buffer.concat(audioChunks)
128
+ const resultMp3Stream = concatUint8Arrays(audioChunks)
128
129
 
129
130
  return resultMp3Stream
130
131
  }
@@ -3,15 +3,14 @@ import WebSocket from 'ws'
3
3
 
4
4
  import { escape } from 'html-escaper'
5
5
 
6
- import splitBuffer from 'buffer-split'
7
-
8
6
  import * as AzureCognitiveServicesTTS from './AzureCognitiveServicesTTS.js'
9
7
  import * as FFMpegTranscoder from '../codecs/FFMpegTranscoder.js'
10
8
  import { Logger } from '../utilities/Logger.js'
11
9
  import { OpenPromise } from '../utilities/OpenPromise.js'
12
- import { getRandomHexString, logToStderr } from '../utilities/Utilities.js'
10
+ import { concatUint8Arrays, getRandomHexString, logToStderr } from '../utilities/Utilities.js'
13
11
  import { RawAudio, getEmptyRawAudio, getRawAudioDuration } from '../audio/AudioUtilities.js'
14
12
  import { Timer } from '../utilities/Timer.js'
13
+ import { decodeUtf8, encodeUtf8 } from '../encodings/Utf8.js'
15
14
 
16
15
  const traceEnabled = false
17
16
 
@@ -50,7 +49,7 @@ export async function synthesize(
50
49
  return { rawAudio, timeline }
51
50
  }
52
51
 
53
- type SynthesisRequestResult = { audioData: Buffer, events: any[] }
52
+ type SynthesisRequestResult = { audioData: Uint8Array, events: any[] }
54
53
 
55
54
  async function requestSynthesis(
56
55
  text: string,
@@ -104,11 +103,11 @@ async function requestSynthesis(
104
103
  throw e
105
104
  }
106
105
 
107
- const receivedBinaryMessages: Buffer[] = []
106
+ const receivedBinaryMessages: Uint8Array[] = []
108
107
  const receivedEventMessages: any[] = []
109
- const audioChunks: Buffer[] = []
108
+ const audioChunks: Uint8Array[] = []
110
109
 
111
- const onMessage = (messageData: Buffer, isBinary: boolean) => {
110
+ const onMessage = (messageData: Uint8Array, isBinary: boolean) => {
112
111
  lastReceievedMessageTime = Timer.currentTime
113
112
 
114
113
  if (isBinary) {
@@ -124,11 +123,11 @@ async function requestSynthesis(
124
123
  log(header)
125
124
 
126
125
  receivedBinaryMessages.push(messageData)
127
- receivedBinaryMessages.push(Buffer.from('\n\n'))
126
+ receivedBinaryMessages.push(encodeUtf8('\n\n'))
128
127
 
129
128
  audioChunks.push(audioChunk)
130
129
  } else {
131
- const message = messageData.toString('utf8')
130
+ const message = decodeUtf8(messageData)
132
131
  const [header, content] = parseTextMessage(message)
133
132
 
134
133
  if (header['X-RequestId'] != requestId) {
@@ -147,7 +146,7 @@ async function requestSynthesis(
147
146
  receivedEventMessages.push(content['Metadata'][0])
148
147
  }
149
148
  else if (header['Path'] == 'turn.end') {
150
- const result: SynthesisRequestResult = { audioData: Buffer.concat(audioChunks), events: receivedEventMessages }
149
+ const result: SynthesisRequestResult = { audioData: concatUint8Arrays(audioChunks), events: receivedEventMessages }
151
150
 
152
151
  removeWebSocketHandlers()
153
152
 
@@ -167,7 +166,7 @@ async function requestSynthesis(
167
166
  }
168
167
  }
169
168
 
170
- const onClose = async (code: number, reason: Buffer) => {
169
+ const onClose = async (code: number, reason: Uint8Array) => {
171
170
  log('WebSocket closed.')
172
171
  log(code)
173
172
  log(reason.toString())
@@ -282,7 +281,7 @@ export async function initializeWebsocketConnection(trustedClientToken: string)
282
281
  requestOpenPromise.resolve(webSocket)
283
282
  }
284
283
 
285
- const onClose = (code: number, reason: Buffer) => {
284
+ const onClose = (code: number, reason: Uint8Array) => {
286
285
  log('WebSocket closed.')
287
286
  log(code)
288
287
  log(reason.toString())
@@ -352,11 +351,44 @@ function parseTextMessage(message: string) {
352
351
  return [parseHeaderString(headerString), JSON.parse(content)]
353
352
  }
354
353
 
355
- function parseBinaryMessage(message: Buffer) {
356
- const audioChunk = splitBuffer(message, Buffer.from('Path:audio\r\n'))[1]
354
+ function parseBinaryMessage(message: Uint8Array) {
355
+ const patternAsBytes = encodeUtf8('Path:audio\r\n')
356
+ const indexOfPattern = indexOfByteSubsequence(message, patternAsBytes)
357
+
358
+ if (indexOfPattern === -1) {
359
+ throw new Error(`Couldn't find separator pattern in Edge TTS binary message`)
360
+ }
361
+
362
+ const audioChunk = message.slice(indexOfPattern + patternAsBytes.length)
363
+
357
364
  const headerBuffer = message.subarray(2, message.length - audioChunk.length)
358
- const headerString = headerBuffer.toString('utf8').trim()
365
+ const headerString = decodeUtf8(headerBuffer).trim()
359
366
 
360
367
  return [parseHeaderString(headerString), audioChunk]
361
368
  }
362
369
 
370
+ function indexOfByteSubsequence(sequence: Uint8Array, subsequence: Uint8Array) {
371
+ function tryMatchAtOffset(offset: number) {
372
+ if (offset + subsequence.length > sequence.length) {
373
+ return false
374
+ }
375
+
376
+ for (let i = 0; i < subsequence.length; i++) {
377
+ if (sequence[offset + i] !== subsequence[i]) {
378
+ return false
379
+ }
380
+ }
381
+
382
+ return true
383
+ }
384
+
385
+ for (let offset = 0; offset < sequence.length; offset++) {
386
+ const matched = tryMatchAtOffset(offset)
387
+
388
+ if (matched) {
389
+ return offset
390
+ }
391
+ }
392
+
393
+ return -1
394
+ }
@@ -107,7 +107,7 @@ export function synthesize(text: string, voiceName: string, rate = 0, useSpeechP
107
107
  EndStream: (streamId: number, streamPos: number) => {
108
108
  clearInterval(dispatchMessagesInterval)
109
109
 
110
- const audioData = Buffer.from(sapiOutputStream.GetData())
110
+ const audioData = new Uint8Array(sapiOutputStream.GetData())
111
111
  const audioChannels = decodeToChannels(audioData, 1, 16, SampleFormat.PCM)
112
112
 
113
113
  WinAX.release(sapiOutputStream)
@@ -92,7 +92,7 @@ export async function synthesizeFragment(text: string, voice: string) {
92
92
  const audioUrl = responseObject.speak_url
93
93
  const audioUrlResponse = await request<ArrayBuffer>({ url: audioUrl, responseType: 'arraybuffer' })
94
94
 
95
- return Buffer.from(audioUrlResponse.data)
95
+ return new Uint8Array(audioUrlResponse.data)
96
96
  }
97
97
 
98
98
  export const voiceList: SynthesisVoice[] = [
@@ -5,7 +5,8 @@ import { bandwidthToQFactor } from '../dsp/BiquadFilter.js'
5
5
  import { Logger } from '../utilities/Logger.js'
6
6
  import { WasmMemoryManager } from '../utilities/WasmMemoryManager.js'
7
7
  import { RawAudio } from '../audio/AudioUtilities.js'
8
- import { readFile } from '../utilities/FileSystem.js'
8
+ import { readFileAsBinary } from '../utilities/FileSystem.js'
9
+ import { concatUint8Arrays } from '../utilities/Utilities.js'
9
10
 
10
11
  let svoxPicoInstance: any
11
12
 
@@ -51,7 +52,7 @@ export async function synthesize(text: string, textAnalysisFilePath: string, sig
51
52
  async function loadResource(localFilePath: string) {
52
53
  const virtualFilePath = '.' + localFilePath.substring(localFilePath.lastIndexOf('/'))
53
54
 
54
- const fileData = await readFile(localFilePath)
55
+ const fileData = await readFileAsBinary(localFilePath)
55
56
  m.FS.writeFile(virtualFilePath, fileData)
56
57
 
57
58
  const virtualFilePathRef = wasmMemory.allocNullTerminatedUtf8String(virtualFilePath)
@@ -108,7 +109,7 @@ export async function synthesize(text: string, textAnalysisFilePath: string, sig
108
109
 
109
110
  const bytesWrittenRef = wasmMemory.allocInt32()
110
111
 
111
- const audioParts: Buffer[] = []
112
+ const audioParts: Uint8Array[] = []
112
113
 
113
114
  for (let textByteOffset = 0; textByteOffset < textRef.length;) {
114
115
  bytesWrittenRef.value = 0
@@ -123,10 +124,10 @@ export async function synthesize(text: string, textAnalysisFilePath: string, sig
123
124
  textByteOffset += bytesWritten
124
125
  }
125
126
 
126
- const audioData = Buffer.concat(audioParts)
127
+ const audioData = concatUint8Arrays(audioParts)
127
128
 
128
129
  function readAudioDataFromEngine() {
129
- const outBuffers: Buffer[] = []
130
+ const outBuffers: Uint8Array[] = []
130
131
 
131
132
  const outBufferLength = 16384
132
133
  const outBufferRef = wasmMemory.allocUint8Array(outBufferLength)
@@ -147,11 +148,11 @@ export async function synthesize(text: string, textAnalysisFilePath: string, sig
147
148
  }
148
149
 
149
150
  if (outByteCount > 0) {
150
- outBuffers.push(Buffer.from(outBufferRef.slice(0, outByteCount)))
151
+ outBuffers.push(outBufferRef.slice(0, outByteCount) as Uint8Array)
151
152
  }
152
153
  }
153
154
 
154
- return Buffer.concat(outBuffers)
155
+ return concatUint8Arrays(outBuffers)
155
156
  }
156
157
 
157
158
  dispose()
@@ -5,9 +5,9 @@ import { RawAudio, getEmptyRawAudio, getRawAudioDuration } from '../audio/AudioU
5
5
  import { Lexicon } from '../nlp/Lexicon.js'
6
6
  import { Timeline } from '../utilities/Timeline.js'
7
7
  import { readAndParseJsonFile, readdir } from '../utilities/FileSystem.js'
8
- import path from 'node:path'
9
8
  import { EspeakOptions, defaultEspeakOptions } from '../synthesis/EspeakTTS.js'
10
9
  import { OnnxExecutionProvider, getOnnxSessionOptions } from '../utilities/OnnxUtilities.js'
10
+ import { joinPath } from '../utilities/PathUtilities.js'
11
11
 
12
12
  const cachedInstanceLookup = new Map<string, VitsTTS>()
13
13
 
@@ -196,7 +196,7 @@ export class VitsTTS {
196
196
  throw new Error(`Couldn't file any ONNX model file in ${this.modelPath}`)
197
197
  }
198
198
 
199
- const onnxModelFilepath = path.join(this.modelPath, onnxModelFilename)
199
+ const onnxModelFilepath = joinPath(this.modelPath, onnxModelFilename)
200
200
 
201
201
  const onnxSessionOptions = getOnnxSessionOptions({ executionProviders: this.executionProviders })
202
202
 
package/src/tests/Test.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { createAlignmentReferenceUsingEspeakForFragments } from '../alignment/SpeechAlignment.js'
2
- import { setVoice } from '../synthesis/EspeakTTS.js'
3
1
  import { logToStderr, setupProgramTerminationListeners } from '../utilities/Utilities.js'
4
2
 
5
3
  const log = logToStderr
@@ -9,32 +7,4 @@ setupProgramTerminationListeners()
9
7
  //process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
10
8
  //process.env.http_proxy = 'http://localhost:8080'
11
9
 
12
- if (false) {
13
- for (let i = 0; i < 1000000; i++) {
14
- if (i % 1000 === 0) {
15
- console.log(`Iteration ${i}`)
16
- }
17
-
18
- await setVoice('en')
19
- }
20
- }
21
-
22
- if (true) {
23
- const fragments: string[] = []
24
-
25
- for (let i = 0; i < 30000; i++) {
26
- fragments.push(`hello`, `${i}`)
27
- }
28
-
29
- await createAlignmentReferenceUsingEspeakForFragments(fragments, {
30
- voice: "gmw/en-US",
31
- ssml: false,
32
- rate: 150,
33
- pitch: 50,
34
- pitchRange: 50,
35
- useKlatt: false,
36
- insertSeparators: true,
37
- })
38
- }
39
-
40
10
  process.exit(0)
@@ -1,8 +1,8 @@
1
- import path from 'path'
2
1
  import { languageCodeToName } from '../utilities/Locale.js'
3
2
  import { OpenPromise } from '../utilities/OpenPromise.js'
4
3
  import { resolveModuleMainPath, roundToDigits } from '../utilities/Utilities.js'
5
4
  import { LanguageDetectionResults } from '../api/LanguageDetectionCommon.js'
5
+ import { getDirName, joinPath } from '../utilities/PathUtilities.js'
6
6
 
7
7
  let fastTextLanguageDetectionModel: any
8
8
 
@@ -41,7 +41,7 @@ async function loadLanguageDetectionModel() {
41
41
  const fastText = new FastText()
42
42
 
43
43
  const moduleMainPath = await resolveModuleMainPath('@echogarden/fasttext-wasm')
44
- const modelPath = path.join(path.dirname(moduleMainPath), 'lid.176.ftz')
44
+ const modelPath = joinPath(getDirName(moduleMainPath), 'lid.176.ftz')
45
45
 
46
46
  const model = await fastText.loadModel(modelPath)
47
47
 
@@ -92,9 +92,7 @@ declare module 'onnxruntime-node' {
92
92
 
93
93
  type RunOptions = InferenceSession.RunOptions
94
94
 
95
- /**
96
- * Binding exports a simple synchronized inference session object wrap.
97
- */
95
+ // Binding exports a simple synchronized inference session object wrap.
98
96
  export namespace Binding {
99
97
  interface InferenceSession {
100
98
  loadModel(modelPath: string, options: SessionOptions): void
@@ -115,5 +113,5 @@ declare module 'onnxruntime-node' {
115
113
  }
116
114
 
117
115
  // From version.d.ts
118
- export const version = '1.16.1'
116
+ export const version = '1.20.0'
119
117
  }
@@ -0,0 +1,5 @@
1
+ export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array
2
+
3
+ export interface TypedArrayConstructor<T extends TypedArray> {
4
+ new(length: number): T
5
+ }
@@ -1,186 +1,112 @@
1
- // Typed arrays to Buffer (little endian) conversions
1
+ // Typed arrays to Uint8Array buffers (little endian) conversions
2
2
  //
3
- // The faster conversion methods (other than the methods for int8) would only work correctly
3
+ // The conversion methods (other than the methods for int8 and int24) would only work correctly
4
4
  // on little-endian architectures, since they assume the byte order of the underlying architecture.
5
5
  //
6
6
  // Since Echogarden only supports little-endian architectures, this shouldn't matter.
7
7
 
8
8
  // int8 <-> bufferLE
9
9
  export function int8ToBuffer(int8s: Int8Array) {
10
- return Buffer.copyBytesFrom(int8s)
10
+ return new Uint8Array(int8s.buffer, int8s.byteOffset, int8s.byteLength)
11
11
  }
12
12
 
13
- export function int8ToBuffer_Slow(int8s: Int8Array) {
14
- const buffer = Buffer.alloc(int8s.length)
15
-
16
- for (let i = 0; i < int8s.length; i++) {
17
- buffer[i] = int8s[i] + 128
18
- }
19
-
20
- return buffer
21
- }
22
-
23
- export function bufferToInt8(buffer: Buffer) {
13
+ export function bufferToInt8(buffer: Uint8Array) {
24
14
  return new Int8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
25
15
  }
26
16
 
27
- export function bufferToInt8_Slow(buffer: Buffer) {
28
- const result = new Int8Array(buffer.length)
29
-
30
- for (let i = 0; i < result.length; i++) {
31
- result[i] = buffer[i] - 128
32
- }
33
-
34
- return result
35
- }
36
-
37
17
  // int16 <-> bufferLE
38
18
  export function int16ToBufferLE(int16s: Int16Array) {
39
- return Buffer.copyBytesFrom(int16s)
40
- }
41
-
42
- export function int16ToBufferLE_Slow(int16s: Int16Array) {
43
- const buffer = Buffer.alloc(int16s.length * 2)
44
-
45
- for (let i = 0; i < int16s.length; i++) {
46
- buffer.writeInt16LE(int16s[i], i * 2)
47
- }
48
-
49
- return buffer
19
+ return new Uint8Array(int16s.buffer, int16s.byteOffset, int16s.byteLength)
50
20
  }
51
21
 
52
- export function bufferLEToInt16(buffer: Buffer) {
22
+ export function bufferLEToInt16(buffer: Uint8Array) {
53
23
  return new Int16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2)
54
24
  }
55
25
 
56
- export function bufferLEToInt16_Slow(buffer: Buffer) {
57
- const result = new Int16Array(buffer.length / 2)
26
+ // int24 <-> bufferLE (uses int32 for storage)
27
+ export function int24ToBufferLE(int24s: Int32Array) {
28
+ const buffer = new Uint8Array(int24s.length * 3)
58
29
 
59
- for (let i = 0; i < result.length; i++) {
60
- result[i] = buffer.readInt16LE(i * 2)
61
- }
30
+ let readOffset = 0
31
+ let writeOffset = 0
62
32
 
63
- return result
64
- }
33
+ while (readOffset < int24s.length) {
34
+ const signedValue = int24s[readOffset++]
65
35
 
66
- // int24 <-> bufferLE (uses int32 for storage)
67
- export function int24ToBufferLE(int24s: Int32Array) {
68
- const buffer = Buffer.alloc(int24s.length * 3)
36
+ let unsignedValue: number
69
37
 
70
- for (let i = 0; i < int24s.length; i++) {
71
- const val = int24s[i]
72
- const encodedVal = val < 0 ? val + 0x1000000 : val
38
+ if (signedValue >= 0) {
39
+ unsignedValue = signedValue
40
+ } else {
41
+ unsignedValue = signedValue + (2 ** 24)
42
+ }
73
43
 
74
- buffer[(i * 3) + 0] = (encodedVal >> 0) & 0xff
75
- buffer[(i * 3) + 1] = (encodedVal >> 8) & 0xff
76
- buffer[(i * 3) + 2] = (encodedVal >> 16) & 0xff
44
+ buffer[writeOffset++] = (unsignedValue) & 0xff
45
+ buffer[writeOffset++] = (unsignedValue >> 8) & 0xff
46
+ buffer[writeOffset++] = (unsignedValue >> 16) & 0xff
77
47
  }
78
48
 
79
49
  return buffer
80
50
  }
81
51
 
82
- export function bufferLEToInt24(buffer: Buffer) {
52
+ export function bufferLEToInt24(buffer: Uint8Array) {
53
+ if (buffer.length % 3 !== 0) {
54
+ throw new Error(`Buffer has a length of ${buffer.length}, which is not a multiple of 3`)
55
+ }
56
+
83
57
  const result = new Int32Array(buffer.length / 3)
84
58
 
85
- for (let i = 0; i < result.length; i++) {
86
- const b0 = buffer[(i * 3) + 0]
87
- const b1 = buffer[(i * 3) + 1]
88
- const b2 = buffer[(i * 3) + 2]
59
+ let readOffset = 0
60
+ let writeOffset = 0
89
61
 
90
- const encodedVal = (b0 << 0) + (b1 << 8) + (b2 << 16)
91
- result[i] = encodedVal > 0x800000 ? encodedVal - 0x1000000 : encodedVal
92
- }
62
+ while (writeOffset < result.length) {
63
+ const b0 = buffer[readOffset++]
64
+ const b1 = buffer[readOffset++]
65
+ const b2 = buffer[readOffset++]
93
66
 
94
- return result
95
- }
67
+ const unsignedValue = (b0) | (b1 << 8) | (b2 << 16)
96
68
 
97
- // int32 <-> bufferLE
98
- export function int32ToBufferLE(int32s: Int32Array) {
99
- return Buffer.copyBytesFrom(int32s)
100
- }
69
+ let signedValue: number
101
70
 
102
- export function int32ToBufferLE_Slow(int32s: Int32Array) {
103
- const buffer = Buffer.alloc(int32s.length * 4)
71
+ if (unsignedValue < 2 ** 23) {
72
+ signedValue = unsignedValue
73
+ } else {
74
+ signedValue = unsignedValue - (2 ** 24)
75
+ }
104
76
 
105
- for (let i = 0; i < int32s.length; i++) {
106
- buffer.writeInt32LE(int32s[i], i * 4)
77
+ result[writeOffset++] = signedValue
107
78
  }
108
79
 
109
- return buffer
80
+ return result
110
81
  }
111
82
 
112
- export function bufferLEToInt32(buffer: Buffer) {
113
- return new Int32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4)
83
+ // int32 <-> bufferLE
84
+ export function int32ToBufferLE(int32s: Int32Array) {
85
+ return new Uint8Array(int32s.buffer, int32s.byteOffset, int32s.byteLength)
114
86
  }
115
87
 
116
- export function bufferLEToInt32_Slow(buffer: Buffer) {
117
- const result = new Int32Array(buffer.length / 4)
118
-
119
- for (let i = 0; i < result.length; i++) {
120
- result[i] = buffer.readInt32LE(i * 4)
121
- }
122
-
123
- return result
88
+ export function bufferLEToInt32(buffer: Uint8Array) {
89
+ return new Int32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4)
124
90
  }
125
91
 
126
92
  // float32 <-> bufferLE
127
93
  export function float32ToBufferLE(float32s: Float32Array) {
128
- return Buffer.copyBytesFrom(float32s)
94
+ return new Uint8Array(float32s.buffer, float32s.byteOffset, float32s.byteLength)
129
95
  }
130
96
 
131
- export function float32ToBufferLE_Slow(float32s: Float32Array) {
132
- const buffer = Buffer.alloc(float32s.length * 4)
133
-
134
- for (let i = 0; i < float32s.length; i++) {
135
- buffer.writeFloatLE(float32s[i], i * 4)
136
- }
137
-
138
- return buffer
139
- }
140
-
141
- export function bufferLEToFloat32(buffer: Buffer) {
97
+ export function bufferLEToFloat32(buffer: Uint8Array) {
142
98
  return new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4)
143
99
  }
144
100
 
145
- export function bufferLEToFloat32_Slow(buffer: Buffer) {
146
- const result = new Float32Array(buffer.length / 4)
147
-
148
- for (let i = 0; i < result.length; i++) {
149
- result[i] = buffer.readFloatLE(i * 4)
150
- }
151
-
152
- return result
153
- }
154
-
155
101
  // float64 <-> bufferLE
156
102
  export function float64ToBufferLE(float64s: Float64Array) {
157
- return Buffer.copyBytesFrom(float64s)
158
- }
159
-
160
- export function float64ToBufferLE_Slow(float64s: Float64Array) {
161
- const buffer = Buffer.alloc(float64s.length * 8)
162
-
163
- for (let i = 0; i < float64s.length; i++) {
164
- buffer.writeDoubleLE(float64s[i], i * 8)
165
- }
166
-
167
- return buffer
103
+ return new Uint8Array(float64s.buffer, float64s.byteOffset, float64s.byteLength)
168
104
  }
169
105
 
170
- export function bufferLEToFloat64(buffer: Buffer) {
106
+ export function bufferLEToFloat64(buffer: Uint8Array) {
171
107
  return new Float64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8)
172
108
  }
173
109
 
174
- export function bufferLEToFloat64_Slow(buffer: Buffer) {
175
- const result = new Float64Array(buffer.length / 8)
176
-
177
- for (let i = 0; i < result.length; i++) {
178
- result[i] = buffer.readDoubleLE(i * 8)
179
- }
180
-
181
- return result
182
- }
183
-
184
110
  // float64 <-> float32
185
111
  export function float64Tofloat32(float64s: Float64Array) {
186
112
  return Float32Array.from(float64s)