mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
Merge branch 'main' into 28060
This commit is contained in:
commit
efdb520414
@ -40,12 +40,14 @@ async function convert(filePath: string, pcmPath: string, logger: LogWrapper): P
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleWavFile(file: Buffer, filePath: string, pcmPath: string, logger: LogWrapper): Promise<Buffer> {
|
async function handleWavFile(
|
||||||
|
file: Buffer, filePath: string, pcmPath: string, logger: LogWrapper
|
||||||
|
): Promise<{input: Buffer, sampleRate: number}> {
|
||||||
const { fmt } = getWavFileInfo(file);
|
const { fmt } = getWavFileInfo(file);
|
||||||
if (!ALLOW_SAMPLE_RATE.includes(fmt.sampleRate)) {
|
if (!ALLOW_SAMPLE_RATE.includes(fmt.sampleRate)) {
|
||||||
return await convert(filePath, pcmPath, logger);
|
return {input: await convert(filePath, pcmPath, logger), sampleRate: 24000};
|
||||||
}
|
}
|
||||||
return file;
|
return {input: file, sampleRate: fmt.sampleRate};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: LogWrapper) {
|
export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: LogWrapper) {
|
||||||
@ -55,8 +57,10 @@ export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: Log
|
|||||||
if (!isSilk(file)) {
|
if (!isSilk(file)) {
|
||||||
logger.log(`语音文件${filePath}需要转换成silk`);
|
logger.log(`语音文件${filePath}需要转换成silk`);
|
||||||
const pcmPath = `${pttPath}.pcm`;
|
const pcmPath = `${pttPath}.pcm`;
|
||||||
const input = isWav(file) ? await handleWavFile(file, filePath, pcmPath, logger) : await convert(filePath, pcmPath, logger);
|
const { input, sampleRate } = isWav(file)
|
||||||
const silk = await encode(input, 24000);
|
? (await handleWavFile(file, filePath, pcmPath, logger))
|
||||||
|
: {input: await convert(filePath, pcmPath, logger), sampleRate: 24000};
|
||||||
|
const silk = await encode(input, sampleRate);
|
||||||
await fsPromise.writeFile(pttPath, silk.data);
|
await fsPromise.writeFile(pttPath, silk.data);
|
||||||
logger.log(`语音文件${filePath}转换成功!`, pttPath, '时长:', silk.duration);
|
logger.log(`语音文件${filePath}转换成功!`, pttPath, '时长:', silk.duration);
|
||||||
return {
|
return {
|
||||||
|
@ -466,7 +466,6 @@ export class OneBotMsgApi {
|
|||||||
sendMsg.data.summary,
|
sendMsg.data.summary,
|
||||||
sendMsg.data.sub_type,
|
sendMsg.data.sub_type,
|
||||||
);
|
);
|
||||||
context.deleteAfterSentFiles.push(sendPicElement.picElement.sourcePath);
|
|
||||||
return sendPicElement;
|
return sendPicElement;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ export class OneBotQuickActionApi {
|
|||||||
const peerContextMode = msg.message_type == 'private' ? ContextMode.Private : ContextMode.Group;
|
const peerContextMode = msg.message_type == 'private' ? ContextMode.Private : ContextMode.Group;
|
||||||
|
|
||||||
const peer: Peer = await createContext(this.core, {
|
const peer: Peer = await createContext(this.core, {
|
||||||
message: "",
|
message_type: undefined,
|
||||||
group_id: msg.group_id?.toString(),
|
group_id: msg.group_id?.toString(),
|
||||||
user_id: msg.user_id?.toString(),
|
user_id: msg.user_id?.toString(),
|
||||||
}, peerContextMode);
|
}, peerContextMode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user