mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 09:15:41 +08:00
feat: mac语音转换silk格式修复
This commit is contained in:
1 parent
5acfa14475
commit
6cbf9af662
14 files changed
+970
-12
No files matched your search
@@ -254,7 +254,7 @@ export function buildPersonalWechatOneBotRequest(
|
||||
}
|
||||
}
|
||||
|
||||
function buildRuntimePath(): string {
|
||||
export function buildPersonalWechatRuntimePath(): string {
|
||||
const existing = String(process.env['PATH'] || '')
|
||||
const bundledFfmpeg = String(ffmpegStaticPath || '')
|
||||
.replace('app.asar', 'app.asar.unpacked')
|
||||
@@ -263,12 +263,25 @@ function buildRuntimePath(): string {
|
||||
return [dirname(bundledFfmpeg), existing].filter(Boolean).join(delimiter)
|
||||
}
|
||||
|
||||
function buildRuntimePythonPath(runtimeRoot: string): string {
|
||||
export function buildPersonalWechatRuntimePythonPath(runtimeRoot: string): string {
|
||||
return [join(runtimeRoot, 'python'), String(process.env['PYTHONPATH'] || '')]
|
||||
.filter(Boolean)
|
||||
.join(delimiter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the same environment used when TraceMemo starts OneBot.
|
||||
* Keep this in one place so runtime checks cannot accidentally inspect a
|
||||
* different Python or ffmpeg than the sender process.
|
||||
*/
|
||||
export function buildPersonalWechatRuntimeEnvironment(runtimeRoot?: string): NodeJS.ProcessEnv {
|
||||
return {
|
||||
...process.env,
|
||||
PATH: buildPersonalWechatRuntimePath(),
|
||||
...(runtimeRoot ? { PYTHONPATH: buildPersonalWechatRuntimePythonPath(runtimeRoot) } : {})
|
||||
}
|
||||
}
|
||||
|
||||
function bundledFfmpegExecutable(): string {
|
||||
const bundledFfmpeg = String(ffmpegStaticPath || '')
|
||||
.replace('app.asar', 'app.asar.unpacked')
|
||||
@@ -282,7 +295,7 @@ async function convertAudioToPcm(audioData: Buffer): Promise<Buffer> {
|
||||
bundledFfmpegExecutable(),
|
||||
['-v', 'error', '-i', 'pipe:0', '-f', 's16le', '-ar', '16000', '-ac', '1', 'pipe:1'],
|
||||
{
|
||||
env: { ...process.env, PATH: buildRuntimePath() },
|
||||
env: buildPersonalWechatRuntimeEnvironment(),
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
windowsHide: true
|
||||
}
|
||||
@@ -1224,6 +1237,13 @@ export class PersonalWechatSendService {
|
||||
this.lastError = ''
|
||||
}
|
||||
|
||||
/** Restart the existing OneBot runtime after an environment change. */
|
||||
async restartRuntime(): Promise<PersonalWechatSenderStatus> {
|
||||
if (process.platform === 'win32') return this.getWindowsStatus()
|
||||
await this.terminate(true)
|
||||
return this.rebind()
|
||||
}
|
||||
|
||||
private async ensureRunning(): Promise<PersonalWechatSenderStatus> {
|
||||
const currentStatus = await this.getStatus()
|
||||
if (currentStatus.state === 'online' || currentStatus.state === 'hook_not_ready') {
|
||||
@@ -1375,6 +1395,7 @@ export class PersonalWechatSendService {
|
||||
try {
|
||||
unlinkSync(temporaryVoicePath)
|
||||
} catch {
|
||||
// Temporary files are best-effort cleanup only.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1386,6 +1407,32 @@ export class PersonalWechatSendService {
|
||||
return preflight.status
|
||||
}
|
||||
|
||||
try {
|
||||
const { personalWechatVoiceEnvironmentService } =
|
||||
await import('./personal-wechat-voice-environment-service')
|
||||
const environment = await personalWechatVoiceEnvironmentService.check()
|
||||
if (!environment.pilk.ready) {
|
||||
appLogger.write({
|
||||
level: 'warn',
|
||||
scope: 'VoiceRuntime',
|
||||
message: 'WARNING: pilk unavailable, OneBot may fallback to go-silk.',
|
||||
details: {
|
||||
python: environment.python.executable,
|
||||
pythonReady: environment.python.ready,
|
||||
ffmpegReady: environment.ffmpeg.ready,
|
||||
runtimeReady: environment.runtimeReady
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
appLogger.write({
|
||||
level: 'warn',
|
||||
scope: 'VoiceRuntime',
|
||||
message: 'Voice encoding environment check failed before OneBot start',
|
||||
details: { error: error instanceof Error ? error.message : String(error) }
|
||||
})
|
||||
}
|
||||
|
||||
const pid = preflight.status.wechatPid
|
||||
const imagePath = findWechatImagePath()
|
||||
this.lastError = ''
|
||||
@@ -1405,11 +1452,7 @@ export class PersonalWechatSendService {
|
||||
detached: true,
|
||||
stdio: 'ignore',
|
||||
windowsHide: true,
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: buildRuntimePath(),
|
||||
PYTHONPATH: buildRuntimePythonPath(preflight.runtime.root)
|
||||
}
|
||||
env: buildPersonalWechatRuntimeEnvironment(preflight.runtime.root)
|
||||
}
|
||||
)
|
||||
this.child = child
|
||||
|
||||
Reference in new issue
Block a user