echogarden 0.12.2 → 1.0.1
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/README.md +15 -14
- package/data/schemas/options.json +398 -111
- package/dist/alignment/DTWMfccSequenceAlignment.d.ts +1 -1
- package/dist/alignment/DTWMfccSequenceAlignment.js +8 -8
- package/dist/alignment/DTWSequenceAlignment.d.ts +1 -1
- package/dist/alignment/DTWSequenceAlignment.js +1 -1
- package/dist/alignment/DTWSequenceAlignmentWindowed.d.ts +1 -1
- package/dist/alignment/DTWSequenceAlignmentWindowed.js +2 -2
- package/dist/alignment/LevenshteinSequenceAlignment.d.ts +1 -1
- package/dist/alignment/LevenshteinSequenceAlignment.js +1 -1
- package/dist/alignment/SpeechAlignment.d.ts +11 -6
- package/dist/alignment/SpeechAlignment.js +113 -71
- package/dist/alignment/SpeechAlignment.js.map +1 -1
- package/dist/api/API.d.ts +13 -12
- package/dist/api/API.js +14 -13
- package/dist/api/API.js.map +1 -1
- package/dist/api/APIOptions.d.ts +5 -4
- package/dist/api/Alignment.d.ts +15 -9
- package/dist/api/Alignment.js +92 -74
- package/dist/api/Alignment.js.map +1 -1
- package/dist/api/Common.js +1 -1
- package/dist/api/Denoising.d.ts +6 -6
- package/dist/api/Denoising.js +23 -23
- package/dist/api/Denoising.js.map +1 -1
- package/dist/api/LanguageDetection.d.ts +19 -12
- package/dist/api/LanguageDetection.js +88 -38
- package/dist/api/LanguageDetection.js.map +1 -1
- package/dist/api/Recognition.d.ts +16 -6
- package/dist/api/Recognition.js +129 -55
- package/dist/api/Recognition.js.map +1 -1
- package/dist/api/SourceSeparation.d.ts +17 -0
- package/dist/api/SourceSeparation.js +61 -0
- package/dist/api/SourceSeparation.js.map +1 -0
- package/dist/api/Synthesis.d.ts +18 -18
- package/dist/api/Synthesis.js +191 -164
- package/dist/api/Synthesis.js.map +1 -1
- package/dist/api/Translation.d.ts +19 -8
- package/dist/api/Translation.js +132 -35
- package/dist/api/Translation.js.map +1 -1
- package/dist/api/Vad.d.ts +10 -5
- package/dist/api/Vad.js +76 -38
- package/dist/api/Vad.js.map +1 -1
- package/dist/audio/AudioBufferConversion.d.ts +1 -1
- package/dist/audio/AudioBufferConversion.js +4 -4
- package/dist/audio/AudioPlayer.d.ts +1 -1
- package/dist/audio/AudioPlayer.js +26 -26
- package/dist/audio/AudioPlayer.js.map +1 -1
- package/dist/audio/AudioRecorder.d.ts +1 -1
- package/dist/audio/AudioRecorder.js +5 -5
- package/dist/audio/AudioUtilities.d.ts +13 -9
- package/dist/audio/AudioUtilities.js +86 -24
- package/dist/audio/AudioUtilities.js.map +1 -1
- package/dist/cli/CLI.d.ts +3 -3
- package/dist/cli/CLI.js +271 -162
- package/dist/cli/CLI.js.map +1 -1
- package/dist/cli/CLIConfigFile.js +8 -8
- package/dist/cli/CLILauncher.js +6 -6
- package/dist/cli/CLIOptionsSchema.js +2 -2
- package/dist/cli/CLIParser.js +5 -5
- package/dist/cli/CLIStarter.js +4 -4
- package/dist/codecs/FFMpegTranscoder.d.ts +2 -2
- package/dist/codecs/FFMpegTranscoder.js +37 -37
- package/dist/codecs/FFMpegTranscoder.js.map +1 -1
- package/dist/codecs/TIMITCodec.js +5 -5
- package/dist/codecs/WaveCodec.d.ts +1 -1
- package/dist/codecs/WaveCodec.js +22 -22
- package/dist/denoising/RNNoise.d.ts +1 -1
- package/dist/denoising/RNNoise.js +9 -9
- package/dist/dsp/BiquadFilter.d.ts +3 -2
- package/dist/dsp/BiquadFilter.js +18 -11
- package/dist/dsp/BiquadFilter.js.map +1 -1
- package/dist/dsp/DecayingPeakEstimator.d.ts +16 -0
- package/dist/dsp/DecayingPeakEstimator.js +23 -0
- package/dist/dsp/DecayingPeakEstimator.js.map +1 -0
- package/dist/dsp/FFT.d.ts +8 -4
- package/dist/dsp/FFT.js +76 -30
- package/dist/dsp/FFT.js.map +1 -1
- package/dist/dsp/KWeightingFilter.d.ts +9 -0
- package/dist/dsp/KWeightingFilter.js +40 -0
- package/dist/dsp/KWeightingFilter.js.map +1 -0
- package/dist/dsp/LoudnessEstimator.d.ts +21 -0
- package/dist/dsp/LoudnessEstimator.js +47 -0
- package/dist/dsp/LoudnessEstimator.js.map +1 -0
- package/dist/dsp/MFCC.d.ts +2 -2
- package/dist/dsp/MFCC.js +15 -15
- package/dist/dsp/MelSpectogram.d.ts +1 -1
- package/dist/dsp/MelSpectogram.js +6 -6
- package/dist/dsp/Rubberband.d.ts +11 -11
- package/dist/dsp/Rubberband.js +27 -27
- package/dist/dsp/Sonic.d.ts +1 -1
- package/dist/dsp/Sonic.js +3 -3
- package/dist/dsp/SpeexResampler.d.ts +1 -1
- package/dist/dsp/SpeexResampler.js +2 -2
- package/dist/math/VectorMath.d.ts +12 -8
- package/dist/math/VectorMath.js +35 -32
- package/dist/math/VectorMath.js.map +1 -1
- package/dist/nlp/ChineseSegmentation.js +2 -2
- package/dist/nlp/CompromiseNLP.js +3 -3
- package/dist/nlp/EspeakPhonemizer.js +30 -30
- package/dist/nlp/IPA.js +20 -20
- package/dist/nlp/JapaneseSegmentation.js +6 -6
- package/dist/nlp/Lexicon.d.ts +1 -1
- package/dist/nlp/Lexicon.js +7 -7
- package/dist/nlp/Segmentation.d.ts +3 -0
- package/dist/nlp/Segmentation.js +21 -14
- package/dist/nlp/Segmentation.js.map +1 -1
- package/dist/nlp/TextNormalizer.js +16 -16
- package/dist/recognition/AmazonTranscribeSTT.d.ts +2 -2
- package/dist/recognition/AmazonTranscribeSTT.js +13 -14
- package/dist/recognition/AmazonTranscribeSTT.js.map +1 -1
- package/dist/recognition/AzureCognitiveServicesSTT.js +5 -6
- package/dist/recognition/AzureCognitiveServicesSTT.js.map +1 -1
- package/dist/recognition/GoogleCloudSTT.d.ts +3 -3
- package/dist/recognition/GoogleCloudSTT.js +18 -18
- package/dist/recognition/OpenAICloudSTT.d.ts +19 -0
- package/dist/recognition/OpenAICloudSTT.js +81 -0
- package/dist/recognition/OpenAICloudSTT.js.map +1 -0
- package/dist/recognition/SileroSTT.d.ts +2 -2
- package/dist/recognition/SileroSTT.js +25 -25
- package/dist/recognition/VoskSTT.d.ts +2 -2
- package/dist/recognition/VoskSTT.js +8 -8
- package/dist/recognition/WhisperCppSTT.d.ts +88 -0
- package/dist/recognition/WhisperCppSTT.js +332 -0
- package/dist/recognition/WhisperCppSTT.js.map +1 -0
- package/dist/recognition/WhisperSTT.d.ts +49 -25
- package/dist/recognition/WhisperSTT.js +626 -481
- package/dist/recognition/WhisperSTT.js.map +1 -1
- package/dist/server/Client.d.ts +1 -1
- package/dist/server/Client.js +22 -22
- package/dist/server/Server.js +9 -9
- package/dist/server/Server.js.map +1 -1
- package/dist/server/Worker.d.ts +22 -22
- package/dist/server/Worker.js +36 -36
- package/dist/server/Worker.js.map +1 -1
- package/dist/server/WorkerStarter.js +2 -2
- package/dist/source-separation/MDXNetSourceSeparation.d.ts +11 -0
- package/dist/source-separation/MDXNetSourceSeparation.js +161 -0
- package/dist/source-separation/MDXNetSourceSeparation.js.map +1 -0
- package/dist/speech-language-detection/SileroLanguageDetection.d.ts +1 -1
- package/dist/speech-language-detection/SileroLanguageDetection.js +7 -7
- package/dist/subtitles/Subtitles.d.ts +10 -0
- package/dist/subtitles/Subtitles.js +2 -2
- package/dist/subtitles/Subtitles.js.map +1 -1
- package/dist/synthesis/AwsPollyTTS.d.ts +1 -1
- package/dist/synthesis/AwsPollyTTS.js +12 -12
- package/dist/synthesis/AzureCognitiveServicesTTS.js +7 -7
- package/dist/synthesis/CoquiServerTTS.js +10 -10
- package/dist/synthesis/CoquiServerTTS.js.map +1 -1
- package/dist/synthesis/ElevenlabsTTS.d.ts +23 -0
- package/dist/synthesis/ElevenlabsTTS.js +103 -0
- package/dist/synthesis/ElevenlabsTTS.js.map +1 -0
- package/dist/synthesis/EspeakTTS.d.ts +6 -5
- package/dist/synthesis/EspeakTTS.js +81 -69
- package/dist/synthesis/EspeakTTS.js.map +1 -1
- package/dist/synthesis/FliteTTS.d.ts +3 -3
- package/dist/synthesis/FliteTTS.js +154 -154
- package/dist/synthesis/FliteTTS.js.map +1 -1
- package/dist/synthesis/GoogleCloudTTS.d.ts +3 -3
- package/dist/synthesis/GoogleCloudTTS.js +17 -17
- package/dist/synthesis/GoogleCloudTTS.js.map +1 -1
- package/dist/synthesis/GoogleTranslateTTS.d.ts +1 -1
- package/dist/synthesis/GoogleTranslateTTS.js +103 -103
- package/dist/synthesis/MicrosoftEdgeTTS.d.ts +2 -2
- package/dist/synthesis/MicrosoftEdgeTTS.js +74 -74
- package/dist/synthesis/OpenAICloudTTS.d.ts +13 -0
- package/dist/synthesis/OpenAICloudTTS.js +169 -0
- package/dist/synthesis/OpenAICloudTTS.js.map +1 -0
- package/dist/synthesis/SamTTS.js +3 -3
- package/dist/synthesis/SapiTTS.d.ts +3 -3
- package/dist/synthesis/SapiTTS.js +26 -26
- package/dist/synthesis/StreamlabsPollyTTS.d.ts +2 -2
- package/dist/synthesis/StreamlabsPollyTTS.js +27 -27
- package/dist/synthesis/SvoxPicoTTS.d.ts +2 -2
- package/dist/synthesis/SvoxPicoTTS.js +65 -65
- package/dist/synthesis/SvoxPicoTTS.js.map +1 -1
- package/dist/synthesis/VitsTTS.d.ts +3 -3
- package/dist/synthesis/VitsTTS.js +378 -378
- package/dist/synthesis/VitsTTS.js.map +1 -1
- package/dist/tests/Test.js +2 -2
- package/dist/utilities/Compression.d.ts +5 -0
- package/dist/utilities/Compression.js +29 -13
- package/dist/utilities/Compression.js.map +1 -1
- package/dist/utilities/FileDownloader.d.ts +1 -1
- package/dist/utilities/FileDownloader.js +16 -16
- package/dist/utilities/FileSystem.js +7 -7
- package/dist/utilities/Locale.d.ts +7 -7
- package/dist/utilities/Locale.js +15 -15
- package/dist/utilities/Logger.js +3 -3
- package/dist/utilities/ObjectUtilities.js +19 -19
- package/dist/utilities/OpenPromise.js +2 -2
- package/dist/utilities/OpenPromise.js.map +1 -1
- package/dist/utilities/PackageManager.js +31 -0
- package/dist/utilities/PackageManager.js.map +1 -1
- package/dist/utilities/PathUtilities.js +8 -8
- package/dist/utilities/RandomGenerator.js +2 -2
- package/dist/utilities/SmoothEstimator.d.ts +8 -0
- package/dist/utilities/SmoothEstimator.js +25 -0
- package/dist/utilities/SmoothEstimator.js.map +1 -0
- package/dist/utilities/TarballMaker.js +8 -8
- package/dist/utilities/Timeline.d.ts +3 -2
- package/dist/utilities/Timeline.js +11 -11
- package/dist/utilities/Timeline.js.map +1 -1
- package/dist/utilities/Timer.js +4 -4
- package/dist/utilities/Utilities.d.ts +4 -0
- package/dist/utilities/Utilities.js +38 -15
- package/dist/utilities/Utilities.js.map +1 -1
- package/dist/utilities/WasmMemoryManager.js +7 -7
- package/dist/utilities/WebReader.js +23 -23
- package/dist/utilities/WikipediaReader.js +2 -2
- package/dist/voice-activity-detection/AdaptiveGateVAD.d.ts +28 -0
- package/dist/voice-activity-detection/AdaptiveGateVAD.js +138 -0
- package/dist/voice-activity-detection/AdaptiveGateVAD.js.map +1 -0
- package/dist/voice-activity-detection/SileroVAD.d.ts +1 -1
- package/dist/voice-activity-detection/SileroVAD.js +5 -5
- package/dist/voice-activity-detection/SileroVAD.js.map +1 -1
- package/dist/voice-activity-detection/WebRtcVAD.d.ts +1 -1
- package/dist/voice-activity-detection/WebRtcVAD.js +4 -4
- package/docs/API.md +29 -11
- package/docs/CLI.md +31 -7
- package/docs/Contributing.md +38 -0
- package/docs/Development.md +91 -19
- package/docs/Engines.md +28 -16
- package/docs/Licenses.md +4 -1
- package/docs/Options.md +159 -79
- package/docs/Releases.md +262 -0
- package/docs/Server.md +7 -7
- package/docs/Tasklist.md +96 -76
- package/docs/Technical.md +4 -4
- package/package.json +13 -14
- package/src/alignment/DTWMfccSequenceAlignment.ts +9 -9
- package/src/alignment/DTWSequenceAlignment.ts +2 -2
- package/src/alignment/DTWSequenceAlignmentWindowed.ts +3 -3
- package/src/alignment/LevenshteinSequenceAlignment.ts +2 -2
- package/src/alignment/SpeechAlignment.ts +195 -86
- package/src/api/API.ts +14 -13
- package/src/api/APIOptions.ts +12 -11
- package/src/api/Alignment.ts +148 -92
- package/src/api/Common.ts +1 -1
- package/src/api/Denoising.ts +28 -28
- package/src/api/LanguageDetection.ts +135 -48
- package/src/api/Recognition.ts +198 -59
- package/src/api/SourceSeparation.ts +99 -0
- package/src/api/Synthesis.ts +217 -181
- package/src/api/Translation.ts +193 -40
- package/src/api/Vad.ts +110 -41
- package/src/audio/AudioBufferConversion.ts +4 -4
- package/src/audio/AudioPlayer.ts +27 -27
- package/src/audio/AudioRecorder.ts +5 -5
- package/src/audio/AudioUtilities.ts +107 -24
- package/src/cli/CLI.ts +313 -164
- package/src/cli/CLIConfigFile.ts +8 -8
- package/src/cli/CLILauncher.ts +6 -6
- package/src/cli/CLIOptionsSchema.ts +2 -2
- package/src/cli/CLIParser.ts +5 -5
- package/src/cli/CLIStarter.ts +4 -4
- package/src/codecs/FFMpegTranscoder.ts +38 -38
- package/src/codecs/TIMITCodec.ts +5 -5
- package/src/codecs/WaveCodec.ts +22 -22
- package/src/denoising/RNNoise.ts +9 -9
- package/src/dsp/BiquadFilter.ts +19 -11
- package/src/dsp/DecayingPeakEstimator.ts +35 -0
- package/src/dsp/FFT.ts +103 -35
- package/src/dsp/KWeightingFilter.ts +43 -0
- package/src/dsp/LoudnessEstimator.ts +74 -0
- package/src/dsp/MFCC.ts +15 -15
- package/src/dsp/MelSpectogram.ts +7 -7
- package/src/dsp/Rubberband.ts +38 -38
- package/src/dsp/Sonic.ts +4 -4
- package/src/dsp/SpeexResampler.ts +2 -2
- package/src/math/VectorMath.ts +42 -33
- package/src/nlp/ChineseSegmentation.ts +3 -3
- package/src/nlp/CompromiseNLP.ts +3 -3
- package/src/nlp/EspeakPhonemizer.ts +30 -30
- package/src/nlp/IPA.ts +20 -20
- package/src/nlp/JapaneseSegmentation.ts +6 -6
- package/src/nlp/Lexicon.ts +8 -8
- package/src/nlp/Segmentation.ts +23 -14
- package/src/nlp/TextNormalizer.ts +16 -16
- package/src/recognition/AmazonTranscribeSTT.ts +16 -17
- package/src/recognition/AzureCognitiveServicesSTT.ts +8 -6
- package/src/recognition/GoogleCloudSTT.ts +21 -21
- package/src/recognition/OpenAICloudSTT.ts +142 -0
- package/src/recognition/SileroSTT.ts +26 -26
- package/src/recognition/VoskSTT.ts +10 -10
- package/src/recognition/WhisperCppSTT.ts +555 -0
- package/src/recognition/WhisperSTT.ts +760 -507
- package/src/server/Client.ts +23 -23
- package/src/server/Server.ts +9 -9
- package/src/server/Worker.ts +53 -53
- package/src/server/WorkerStarter.ts +2 -2
- package/src/source-separation/MDXNetSourceSeparation.ts +228 -0
- package/src/speech-language-detection/SileroLanguageDetection.ts +8 -8
- package/src/subtitles/Subtitles.ts +3 -3
- package/src/synthesis/AwsPollyTTS.ts +14 -14
- package/src/synthesis/AzureCognitiveServicesTTS.ts +10 -10
- package/src/synthesis/CoquiServerTTS.ts +10 -10
- package/src/synthesis/ElevenlabsTTS.ts +137 -0
- package/src/synthesis/EspeakTTS.ts +90 -71
- package/src/synthesis/FliteTTS.ts +157 -157
- package/src/synthesis/GoogleCloudTTS.ts +19 -19
- package/src/synthesis/GoogleTranslateTTS.ts +104 -104
- package/src/synthesis/MicrosoftEdgeTTS.ts +80 -80
- package/src/synthesis/OpenAICloudTTS.ts +196 -0
- package/src/synthesis/SamTTS.ts +3 -3
- package/src/synthesis/SapiTTS.ts +29 -29
- package/src/synthesis/StreamlabsPollyTTS.ts +29 -29
- package/src/synthesis/SvoxPicoTTS.ts +67 -67
- package/src/synthesis/VitsTTS.ts +380 -380
- package/src/tests/Test.ts +4 -4
- package/src/utilities/Compression.ts +34 -13
- package/src/utilities/FileDownloader.ts +19 -19
- package/src/utilities/FileSystem.ts +7 -7
- package/src/utilities/Locale.ts +22 -22
- package/src/utilities/Logger.ts +4 -4
- package/src/utilities/ObjectUtilities.ts +19 -19
- package/src/utilities/OpenPromise.ts +2 -2
- package/src/utilities/PackageManager.ts +40 -0
- package/src/utilities/PathUtilities.ts +8 -8
- package/src/utilities/RandomGenerator.ts +3 -3
- package/src/utilities/SmoothEstimator.ts +35 -0
- package/src/utilities/TarballMaker.ts +9 -9
- package/src/utilities/Timeline.ts +15 -13
- package/src/utilities/Timer.ts +4 -4
- package/src/utilities/Utilities.ts +49 -15
- package/src/utilities/WasmMemoryManager.ts +7 -7
- package/src/utilities/WebReader.ts +23 -23
- package/src/utilities/WikipediaReader.ts +2 -2
- package/src/voice-activity-detection/AdaptiveGateVAD.ts +202 -0
- package/src/voice-activity-detection/SileroVAD.ts +5 -5
- package/src/voice-activity-detection/WebRtcVAD.ts +5 -5
- package/dist/synthesis/ElevenLabsTTS.d.ts +0 -8
- package/dist/synthesis/ElevenLabsTTS.js +0 -82
- package/dist/synthesis/ElevenLabsTTS.js.map +0 -1
- package/src/synthesis/ElevenLabsTTS.ts +0 -104
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { request } from
|
|
2
|
-
import { Phrase, splitToFragments } from
|
|
3
|
-
import { concatFloat32Arrays, logToStderr } from
|
|
4
|
-
import * as FFMpegTranscoder from
|
|
5
|
-
import { trimAudioEnd } from
|
|
6
|
-
import { Logger } from
|
|
7
|
-
import { Timeline } from
|
|
8
|
-
import { getShortLanguageCode } from
|
|
1
|
+
import { request } from 'gaxios'
|
|
2
|
+
import { Phrase, splitToFragments } from '../nlp/Segmentation.js'
|
|
3
|
+
import { concatFloat32Arrays, logToStderr } from '../utilities/Utilities.js'
|
|
4
|
+
import * as FFMpegTranscoder from '../codecs/FFMpegTranscoder.js'
|
|
5
|
+
import { trimAudioEnd } from '../audio/AudioUtilities.js'
|
|
6
|
+
import { Logger } from '../utilities/Logger.js'
|
|
7
|
+
import { Timeline } from '../utilities/Timeline.js'
|
|
8
|
+
import { getShortLanguageCode } from '../utilities/Locale.js'
|
|
9
9
|
|
|
10
10
|
const log = logToStderr
|
|
11
11
|
|
|
12
12
|
const maxTextLengthPerRequest = 200
|
|
13
13
|
|
|
14
|
-
export async function synthesizeLongText(text: string, languageCode =
|
|
14
|
+
export async function synthesizeLongText(text: string, languageCode = 'en', tld = 'us', sentenceEndPause = 0.75, segmentEndPause = 1.0) {
|
|
15
15
|
if (text.length == 0) {
|
|
16
|
-
throw new Error(
|
|
16
|
+
throw new Error('Text is empty')
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const logger = new Logger()
|
|
20
|
-
logger.start(
|
|
20
|
+
logger.start('Prepare and split text')
|
|
21
21
|
|
|
22
22
|
const fragments = await splitToFragments(text, maxTextLengthPerRequest, languageCode)
|
|
23
23
|
|
|
@@ -57,7 +57,7 @@ export async function synthesizeLongText(text: string, languageCode = "en", tld
|
|
|
57
57
|
const endTime = startTime + (trimmedAudio.length / fragmentsSampleRate)
|
|
58
58
|
|
|
59
59
|
timeline.push({
|
|
60
|
-
type:
|
|
60
|
+
type: 'segment',
|
|
61
61
|
text: fragment.text,
|
|
62
62
|
startTime,
|
|
63
63
|
endTime
|
|
@@ -74,56 +74,56 @@ export async function synthesizeLongText(text: string, languageCode = "en", tld
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
export async function synthesizeShortText(text: string, languageCode =
|
|
77
|
+
export async function synthesizeShortText(text: string, languageCode = 'en', tld = 'us') {
|
|
78
78
|
if (text.length > maxTextLengthPerRequest) {
|
|
79
79
|
throw new Error(`Text is ${text.length} characters, which is longer than the maximum of ${maxTextLengthPerRequest}`)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
if (languageCode !=
|
|
82
|
+
if (languageCode != 'zh-CN' && languageCode != 'zh-TW') {
|
|
83
83
|
languageCode = getShortLanguageCode(languageCode)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const bodyFormParameters = [text, languageCode, null,
|
|
87
|
-
const requestForm = [[[
|
|
86
|
+
const bodyFormParameters = [text, languageCode, null, 'null']
|
|
87
|
+
const requestForm = [[['jQ1olc', JSON.stringify(bodyFormParameters), null, 'generic']]]
|
|
88
88
|
const stringifiedForm = JSON.stringify(requestForm)
|
|
89
89
|
const requestBody = `f.req=${encodeURIComponent(stringifiedForm)}&`
|
|
90
90
|
|
|
91
91
|
const response = await request<string>({
|
|
92
|
-
method:
|
|
92
|
+
method: 'POST',
|
|
93
93
|
|
|
94
94
|
url: `https://translate.google.${tld}/_/TranslateWebserverUi/data/batchexecute`,
|
|
95
95
|
|
|
96
96
|
params: {
|
|
97
|
-
|
|
97
|
+
'rpcids': 'jQ1olc'
|
|
98
98
|
},
|
|
99
99
|
|
|
100
100
|
headers: {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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',
|
|
122
122
|
},
|
|
123
123
|
|
|
124
124
|
body: requestBody,
|
|
125
125
|
|
|
126
|
-
responseType:
|
|
126
|
+
responseType: 'text'
|
|
127
127
|
})
|
|
128
128
|
|
|
129
129
|
//log(response.data)
|
|
@@ -135,7 +135,7 @@ export async function synthesizeShortText(text: string, languageCode = "en", tld
|
|
|
135
135
|
|
|
136
136
|
if (match != null) {
|
|
137
137
|
const base64AudioChunk = match[1]
|
|
138
|
-
audioChunks.push(Buffer.from(base64AudioChunk,
|
|
138
|
+
audioChunks.push(Buffer.from(base64AudioChunk, 'base64'))
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
@@ -144,67 +144,67 @@ export async function synthesizeShortText(text: string, languageCode = "en", tld
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
export const supportedLanguageLookup: { [langCode: string]: string } = {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
147
|
+
'af': 'Afrikaans',
|
|
148
|
+
'ar': 'Arabic',
|
|
149
|
+
'bg': 'Bulgarian',
|
|
150
|
+
'bn': 'Bengali',
|
|
151
|
+
'bs': 'Bosnian',
|
|
152
|
+
'ca': 'Catalan',
|
|
153
|
+
'cs': 'Czech',
|
|
154
|
+
'cy': 'Welsh',
|
|
155
|
+
'da': 'Danish',
|
|
156
|
+
'de': 'German',
|
|
157
|
+
'el': 'Greek',
|
|
158
|
+
'en': 'English',
|
|
159
|
+
'eo': 'Esperanto',
|
|
160
|
+
'es': 'Spanish',
|
|
161
|
+
'et': 'Estonian',
|
|
162
|
+
'fi': 'Finnish',
|
|
163
|
+
'fr': 'French',
|
|
164
|
+
'gu': 'Gujarati',
|
|
165
|
+
'hi': 'Hindi',
|
|
166
|
+
'hr': 'Croatian',
|
|
167
|
+
'hu': 'Hungarian',
|
|
168
|
+
'hy': 'Armenian',
|
|
169
|
+
'id': 'Indonesian',
|
|
170
|
+
'is': 'Icelandic',
|
|
171
|
+
'it': 'Italian',
|
|
172
|
+
'iw': 'Hebrew',
|
|
173
|
+
'ja': 'Japanese',
|
|
174
|
+
'jw': 'Javanese',
|
|
175
|
+
'km': 'Khmer',
|
|
176
|
+
'kn': 'Kannada',
|
|
177
|
+
'ko': 'Korean',
|
|
178
|
+
'la': 'Latin',
|
|
179
|
+
'lv': 'Latvian',
|
|
180
|
+
'mk': 'Macedonian',
|
|
181
|
+
'ms': 'Malay',
|
|
182
|
+
'ml': 'Malayalam',
|
|
183
|
+
'mr': 'Marathi',
|
|
184
|
+
'my': 'Myanmar (Burmese)',
|
|
185
|
+
'ne': 'Nepali',
|
|
186
|
+
'nl': 'Dutch',
|
|
187
|
+
'no': 'Norwegian',
|
|
188
|
+
'pl': 'Polish',
|
|
189
|
+
'pt': 'Portuguese',
|
|
190
|
+
'ro': 'Romanian',
|
|
191
|
+
'ru': 'Russian',
|
|
192
|
+
'si': 'Sinhala',
|
|
193
|
+
'sk': 'Slovak',
|
|
194
|
+
'sq': 'Albanian',
|
|
195
|
+
'sr': 'Serbian',
|
|
196
|
+
'su': 'Sundanese',
|
|
197
|
+
'sv': 'Swedish',
|
|
198
|
+
'sw': 'Swahili',
|
|
199
|
+
'ta': 'Tamil',
|
|
200
|
+
'te': 'Telugu',
|
|
201
|
+
'th': 'Thai',
|
|
202
|
+
'tl': 'Filipino',
|
|
203
|
+
'tr': 'Turkish',
|
|
204
|
+
'uk': 'Ukrainian',
|
|
205
|
+
'ur': 'Urdu',
|
|
206
|
+
'vi': 'Vietnamese',
|
|
207
|
+
'zh-CN': 'Chinese',
|
|
208
|
+
'zh-TW': 'Chinese (Mandarin/Taiwan)',
|
|
209
|
+
'zh': 'Chinese (Mandarin)',
|
|
210
210
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { request } from
|
|
2
|
-
import WebSocket from
|
|
1
|
+
import { request } from 'gaxios'
|
|
2
|
+
import WebSocket from 'ws'
|
|
3
3
|
|
|
4
4
|
import { escape } from 'html-escaper'
|
|
5
5
|
|
|
6
|
-
import splitBuffer from
|
|
6
|
+
import splitBuffer from 'buffer-split'
|
|
7
7
|
|
|
8
|
-
import * as AzureCognitiveServicesTTS from
|
|
9
|
-
import * as FFMpegTranscoder from
|
|
10
|
-
import { Logger } from
|
|
11
|
-
import { OpenPromise } from
|
|
12
|
-
import { getRandomHexString, logToStderr } from
|
|
13
|
-
import { RawAudio, getEmptyRawAudio, getRawAudioDuration } from
|
|
14
|
-
import { Timer } from
|
|
8
|
+
import * as AzureCognitiveServicesTTS from './AzureCognitiveServicesTTS.js'
|
|
9
|
+
import * as FFMpegTranscoder from '../codecs/FFMpegTranscoder.js'
|
|
10
|
+
import { Logger } from '../utilities/Logger.js'
|
|
11
|
+
import { OpenPromise } from '../utilities/OpenPromise.js'
|
|
12
|
+
import { getRandomHexString, logToStderr } from '../utilities/Utilities.js'
|
|
13
|
+
import { RawAudio, getEmptyRawAudio, getRawAudioDuration } from '../audio/AudioUtilities.js'
|
|
14
|
+
import { Timer } from '../utilities/Timer.js'
|
|
15
15
|
|
|
16
16
|
const traceEnabled = false
|
|
17
17
|
|
|
@@ -20,13 +20,13 @@ const log: typeof logToStderr = traceEnabled ? logToStderr : () => { }
|
|
|
20
20
|
export async function synthesize(
|
|
21
21
|
text: string,
|
|
22
22
|
trustedClientToken: string,
|
|
23
|
-
voice =
|
|
24
|
-
ssmlPitchString =
|
|
25
|
-
ssmlRateString =
|
|
26
|
-
ssmlVolumeString =
|
|
23
|
+
voice = 'Microsoft Server Speech Text to Speech Voice (en-US, AvaNeural)',
|
|
24
|
+
ssmlPitchString = '+0Hz',
|
|
25
|
+
ssmlRateString = '+0%',
|
|
26
|
+
ssmlVolumeString = '+0%') {
|
|
27
27
|
|
|
28
28
|
const logger = new Logger()
|
|
29
|
-
logger.start(
|
|
29
|
+
logger.start('Request synthesis from Microsoft Edge cloud API')
|
|
30
30
|
|
|
31
31
|
const { audioData, events } = await requestSynthesis(text, trustedClientToken, voice, ssmlPitchString, ssmlRateString, ssmlVolumeString)
|
|
32
32
|
logger.end()
|
|
@@ -43,7 +43,7 @@ export async function synthesize(
|
|
|
43
43
|
|
|
44
44
|
//logToStderr(`Raw audio length: ${rawAudio.audioChannels[0].length}`)
|
|
45
45
|
|
|
46
|
-
logger.start(
|
|
46
|
+
logger.start('Convert boundary events to timeline')
|
|
47
47
|
const timeline = AzureCognitiveServicesTTS.boundaryEventsToTimeline(events, getRawAudioDuration(rawAudio))
|
|
48
48
|
logger.end()
|
|
49
49
|
|
|
@@ -55,10 +55,10 @@ type SynthesisRequestResult = { audioData: Buffer, events: any[] }
|
|
|
55
55
|
async function requestSynthesis(
|
|
56
56
|
text: string,
|
|
57
57
|
trustedClientToken: string,
|
|
58
|
-
voice =
|
|
59
|
-
ssmlPitchString =
|
|
60
|
-
ssmlRateString =
|
|
61
|
-
ssmlVolumeString =
|
|
58
|
+
voice = 'Microsoft Server Speech Text to Speech Voice (en-US, AriaNeural)',
|
|
59
|
+
ssmlPitchString = '+0Hz',
|
|
60
|
+
ssmlRateString = '+0%',
|
|
61
|
+
ssmlVolumeString = '+0%') {
|
|
62
62
|
|
|
63
63
|
const synthesisOpenPromise = new OpenPromise<SynthesisRequestResult>()
|
|
64
64
|
|
|
@@ -120,15 +120,15 @@ async function requestSynthesis(
|
|
|
120
120
|
return
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
log(
|
|
123
|
+
log('\nReceived binary message:')
|
|
124
124
|
log(header)
|
|
125
125
|
|
|
126
126
|
receivedBinaryMessages.push(messageData)
|
|
127
|
-
receivedBinaryMessages.push(Buffer.from(
|
|
127
|
+
receivedBinaryMessages.push(Buffer.from('\n\n'))
|
|
128
128
|
|
|
129
129
|
audioChunks.push(audioChunk)
|
|
130
130
|
} else {
|
|
131
|
-
const message = messageData.toString(
|
|
131
|
+
const message = messageData.toString('utf8')
|
|
132
132
|
const [header, content] = parseTextMessage(message)
|
|
133
133
|
|
|
134
134
|
if (header['X-RequestId'] != requestId) {
|
|
@@ -136,17 +136,17 @@ async function requestSynthesis(
|
|
|
136
136
|
return
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
log(
|
|
139
|
+
log('\nReceived text message:')
|
|
140
140
|
log(header)
|
|
141
141
|
log(content)
|
|
142
142
|
|
|
143
|
-
if (header[
|
|
143
|
+
if (header['Path'] == 'turn.start') {
|
|
144
144
|
|
|
145
145
|
}
|
|
146
|
-
else if (header[
|
|
147
|
-
receivedEventMessages.push(content[
|
|
146
|
+
else if (header['Path'] == 'audio.metadata') {
|
|
147
|
+
receivedEventMessages.push(content['Metadata'][0])
|
|
148
148
|
}
|
|
149
|
-
else if (header[
|
|
149
|
+
else if (header['Path'] == 'turn.end') {
|
|
150
150
|
const result: SynthesisRequestResult = { audioData: Buffer.concat(audioChunks), events: receivedEventMessages }
|
|
151
151
|
|
|
152
152
|
removeWebSocketHandlers()
|
|
@@ -168,7 +168,7 @@ async function requestSynthesis(
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
const onClose = async (code: number, reason: Buffer) => {
|
|
171
|
-
log(
|
|
171
|
+
log('WebSocket closed.')
|
|
172
172
|
log(code)
|
|
173
173
|
log(reason.toString())
|
|
174
174
|
|
|
@@ -179,15 +179,15 @@ async function requestSynthesis(
|
|
|
179
179
|
|
|
180
180
|
function removeWebSocketHandlers() {
|
|
181
181
|
if (webSocket) {
|
|
182
|
-
webSocket.off(
|
|
183
|
-
webSocket.off(
|
|
184
|
-
webSocket.off(
|
|
182
|
+
webSocket.off('message', onMessage)
|
|
183
|
+
webSocket.off('error', onError)
|
|
184
|
+
webSocket.off('close', onClose)
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
webSocket.on(
|
|
189
|
-
webSocket.on(
|
|
190
|
-
webSocket.on(
|
|
188
|
+
webSocket.on('message', onMessage)
|
|
189
|
+
webSocket.on('error', onError)
|
|
190
|
+
webSocket.on('close', onClose)
|
|
191
191
|
|
|
192
192
|
const requestContentSSML =
|
|
193
193
|
`<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>` +
|
|
@@ -201,7 +201,7 @@ async function requestSynthesis(
|
|
|
201
201
|
const bodyRequestString =
|
|
202
202
|
`X-RequestId:${requestId}\r\n` +
|
|
203
203
|
`Content-Type:application/ssml+xml\r\n` +
|
|
204
|
-
`X-Timestamp:${getTimestampString()}Z\r\n` + // The added
|
|
204
|
+
`X-Timestamp:${getTimestampString()}Z\r\n` + // The added 'Z' recreates a Microsoft Edge bug.
|
|
205
205
|
`Path:ssml\r\n\r\n` +
|
|
206
206
|
requestContentSSML
|
|
207
207
|
|
|
@@ -229,34 +229,34 @@ export async function initializeWebsocketConnection(trustedClientToken: string)
|
|
|
229
229
|
|
|
230
230
|
const connectionId = getRandomHexString()
|
|
231
231
|
|
|
232
|
-
const requestURL =
|
|
233
|
-
|
|
232
|
+
const requestURL = 'wss://speech.platform.bing.com/' +
|
|
233
|
+
'consumer/speech/synthesize/readaloud/edge/v1' +
|
|
234
234
|
`?TrustedClientToken=${trustedClientToken}` +
|
|
235
|
-
|
|
235
|
+
'&ConnectionId=' + connectionId
|
|
236
236
|
|
|
237
237
|
log(requestURL)
|
|
238
|
-
log(
|
|
238
|
+
log('')
|
|
239
239
|
|
|
240
240
|
const webSocket = new WebSocket(requestURL, {
|
|
241
241
|
headers: {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
'Pragma': 'no-cache',
|
|
243
|
+
'Cache-Control': 'no-cache',
|
|
244
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36 Edg/103.0.1264.44',
|
|
245
|
+
'Origin': 'chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold',
|
|
246
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
|
247
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
248
248
|
}
|
|
249
249
|
})
|
|
250
250
|
|
|
251
251
|
const requestMetadata = {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
'context': {
|
|
253
|
+
'synthesis': {
|
|
254
|
+
'audio': {
|
|
255
|
+
'metadataoptions': {
|
|
256
|
+
'sentenceBoundaryEnabled': 'false',
|
|
257
|
+
'wordBoundaryEnabled': 'true'
|
|
258
258
|
},
|
|
259
|
-
|
|
259
|
+
'outputFormat': 'webm-24khz-16bit-mono-opus'
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
}
|
|
@@ -275,15 +275,15 @@ export async function initializeWebsocketConnection(trustedClientToken: string)
|
|
|
275
275
|
|
|
276
276
|
existingWebSocketConnection = webSocket
|
|
277
277
|
|
|
278
|
-
webSocket.off(
|
|
279
|
-
webSocket.off(
|
|
280
|
-
webSocket.off(
|
|
278
|
+
webSocket.off('open', onOpen)
|
|
279
|
+
webSocket.off('close', onClose)
|
|
280
|
+
webSocket.off('error', onError)
|
|
281
281
|
|
|
282
282
|
requestOpenPromise.resolve(webSocket)
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
const onClose = (code: number, reason: Buffer) => {
|
|
286
|
-
log(
|
|
286
|
+
log('WebSocket closed.')
|
|
287
287
|
log(code)
|
|
288
288
|
log(reason.toString())
|
|
289
289
|
|
|
@@ -296,50 +296,50 @@ export async function initializeWebsocketConnection(trustedClientToken: string)
|
|
|
296
296
|
requestOpenPromise.reject(err)
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
webSocket.on(
|
|
300
|
-
webSocket.on(
|
|
301
|
-
webSocket.on(
|
|
299
|
+
webSocket.on('open', onOpen)
|
|
300
|
+
webSocket.on('close', onClose)
|
|
301
|
+
webSocket.on('error', onError)
|
|
302
302
|
|
|
303
303
|
return requestOpenPromise.promise
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
export async function getVoiceList(trustedClientToken: string) {
|
|
307
307
|
const response = await request<any>({
|
|
308
|
-
method:
|
|
308
|
+
method: 'GET',
|
|
309
309
|
|
|
310
|
-
url:
|
|
310
|
+
url: 'https://speech.platform.bing.com/consumer/speech/synthesize/' +
|
|
311
311
|
`readaloud/voices/list?trustedclienttoken=${trustedClientToken}`,
|
|
312
312
|
|
|
313
313
|
headers: {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
314
|
+
'sec-ch-ua': `" Not;A Brand";v="99", "Microsoft Edge";v="103", "Chromium";v="103"`,
|
|
315
|
+
'dnt': '1',
|
|
316
|
+
'sec-ch-ua-mobile': '?0',
|
|
317
|
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36 Edg/103.0.1264.44',
|
|
318
|
+
'sec-ch-ua-platform': 'Windows',
|
|
319
|
+
'accept': '*/*',
|
|
320
|
+
'sec-fetch-site': 'none',
|
|
321
|
+
'sec-fetch-mode': 'cors',
|
|
322
|
+
'sec-fetch-dest': 'empty',
|
|
323
|
+
'accept-encoding': 'gzip, deflate, br',
|
|
324
|
+
'accept-language': 'en-US,en;q=0.9',
|
|
325
325
|
},
|
|
326
326
|
|
|
327
|
-
responseType:
|
|
327
|
+
responseType: 'json'
|
|
328
328
|
})
|
|
329
329
|
|
|
330
330
|
return response.data as any[]
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
function getTimestampString() {
|
|
334
|
-
const timestampString = new Date(new Date().toLocaleString(
|
|
334
|
+
const timestampString = new Date(new Date().toLocaleString('en-US', { timeZone: 'UTC' })).toString().replace(/GMT.*/, 'GMT+0000 (Coordinated Universal Time)')
|
|
335
335
|
return timestampString
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
function parseHeaderString(headerString: string) {
|
|
339
339
|
const headers: any = {}
|
|
340
340
|
|
|
341
|
-
for (const headerLine of headerString.split(
|
|
342
|
-
const [key, value] = headerLine.split(
|
|
341
|
+
for (const headerLine of headerString.split('\r\n')) {
|
|
342
|
+
const [key, value] = headerLine.split(':')
|
|
343
343
|
headers[key] = value
|
|
344
344
|
}
|
|
345
345
|
|
|
@@ -347,15 +347,15 @@ function parseHeaderString(headerString: string) {
|
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
function parseTextMessage(message: string) {
|
|
350
|
-
const [headerString, content] = message.split(
|
|
350
|
+
const [headerString, content] = message.split('\r\n\r\n')
|
|
351
351
|
|
|
352
352
|
return [parseHeaderString(headerString), JSON.parse(content)]
|
|
353
353
|
}
|
|
354
354
|
|
|
355
355
|
function parseBinaryMessage(message: Buffer) {
|
|
356
|
-
const audioChunk = splitBuffer(message, Buffer.from(
|
|
356
|
+
const audioChunk = splitBuffer(message, Buffer.from('Path:audio\r\n'))[1]
|
|
357
357
|
const headerBuffer = message.subarray(2, message.length - audioChunk.length)
|
|
358
|
-
const headerString = headerBuffer.toString(
|
|
358
|
+
const headerString = headerBuffer.toString('utf8').trim()
|
|
359
359
|
|
|
360
360
|
return [parseHeaderString(headerString), audioChunk]
|
|
361
361
|
}
|