This commit is contained in:
idranme 2024-10-11 13:38:59 +08:00
parent 433a175809
commit abb468c3f8
3 changed files with 40 additions and 49 deletions

View File

@ -53,7 +53,6 @@ function convert(ctx: Context, input: Input, options: FFmpegOptions, outputPath?
} }
export async function encodeSilk(ctx: Context, filePath: string) { export async function encodeSilk(ctx: Context, filePath: string) {
try {
const file = await fsPromise.readFile(filePath) const file = await fsPromise.readFile(filePath)
if (!isSilk(file)) { if (!isSilk(file)) {
ctx.logger.info(`语音文件${filePath}需要转换成silk`) ctx.logger.info(`语音文件${filePath}需要转换成silk`)
@ -93,10 +92,6 @@ export async function encodeSilk(ctx: Context, filePath: string) {
duration, duration,
} }
} }
} catch (err) {
ctx.logger.error('convert silk failed', (err as Error).stack)
return {}
}
} }
type OutFormat = 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac' type OutFormat = 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'

View File

@ -210,13 +210,9 @@ export namespace SendElement {
export async function ptt(ctx: Context, pttPath: string): Promise<SendPttElement> { export async function ptt(ctx: Context, pttPath: string): Promise<SendPttElement> {
const { converted, path: silkPath, duration } = await encodeSilk(ctx, pttPath) const { converted, path: silkPath, duration } = await encodeSilk(ctx, pttPath)
if (!silkPath) {
throw '语音转换失败, 请检查语音文件是否正常'
}
// log("生成语音", silkPath, duration);
const { md5, fileName, path, fileSize } = await ctx.ntFileApi.uploadFile(silkPath, ElementType.Ptt) const { md5, fileName, path, fileSize } = await ctx.ntFileApi.uploadFile(silkPath, ElementType.Ptt)
if (fileSize === 0) { if (fileSize === 0) {
throw '文件异常,大小为0' throw new Error('文件异常,大小为 0')
} }
if (converted) { if (converted) {
unlink(silkPath) unlink(silkPath)

View File

@ -180,19 +180,19 @@ class OneBot11Adapter extends Service {
msg.target_id = parseInt(message.peerUin) msg.target_id = parseInt(message.peerUin)
} }
this.dispatch(msg) this.dispatch(msg)
}).catch(e => this.ctx.logger.error('constructMessage error: ', e.stack.toString())) }).catch(e => this.ctx.logger.error('handling incoming messages', e))
OB11Entities.groupEvent(this.ctx, message).then(groupEvent => { OB11Entities.groupEvent(this.ctx, message).then(groupEvent => {
if (groupEvent) { if (groupEvent) {
this.dispatch(groupEvent) this.dispatch(groupEvent)
} }
}) }).catch(e => this.ctx.logger.error('handling incoming group events', e))
OB11Entities.privateEvent(this.ctx, message).then(privateEvent => { OB11Entities.privateEvent(this.ctx, message).then(privateEvent => {
if (privateEvent) { if (privateEvent) {
this.dispatch(privateEvent) this.dispatch(privateEvent)
} }
}) }).catch(e => this.ctx.logger.error('handling incoming buddy events', e))
} }
private handleRecallMsg(message: RawMessage) { private handleRecallMsg(message: RawMessage) {