mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 09:15:41 +08:00
feat: 增加windows发送能力
抽离功能到设置页面 抽离文字转语音功能
This commit is contained in:
1 parent
698251796f
commit
5acfa14475
33 files changed
+2226
-905
No files matched your search
@@ -24,6 +24,11 @@ export interface VoiceAudioDecoder {
|
||||
decode(source: EncodedVoiceSource): Promise<DecodedVoiceAudio>
|
||||
}
|
||||
|
||||
export interface EncodedSilkAudio {
|
||||
data: Buffer
|
||||
durationMs: number
|
||||
}
|
||||
|
||||
export type SilkWasmRuntimeLocation = {
|
||||
packagePath: string
|
||||
wasmPath: string
|
||||
@@ -86,6 +91,23 @@ export class SilkAudioDecoder implements VoiceAudioDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
export class SilkAudioEncoder {
|
||||
async encode(pcm: Buffer, sampleRate: number): Promise<EncodedSilkAudio> {
|
||||
const locations = getSilkWasmRuntimeLocations()
|
||||
const runtime = findSilkWasmRuntimeLocation(locations)
|
||||
if (!runtime) throw new Error('silk.wasm 未找到')
|
||||
const silkWasm = nodeRequire(runtime.packagePath) as {
|
||||
encode?: (
|
||||
data: Buffer,
|
||||
sampleRate: number
|
||||
) => Promise<{ data: Uint8Array; duration?: number }>
|
||||
}
|
||||
if (!silkWasm.encode) throw new Error('silk-wasm 运行时无效')
|
||||
const result = await silkWasm.encode(pcm, sampleRate)
|
||||
return { data: Buffer.from(result.data), durationMs: Math.round(Number(result.duration) || 0) }
|
||||
}
|
||||
}
|
||||
|
||||
export class AudioDecoderRegistry {
|
||||
private readonly decoders = new Map<string, VoiceAudioDecoder>()
|
||||
|
||||
|
||||
Reference in new issue
Block a user