尝试发送语音

This commit is contained in:
linyuchen
2023-11-09 17:39:31 +08:00
parent 97a315cd8a
commit 2c7e5ad090
4 changed files with 71 additions and 2 deletions

View File

@@ -7,6 +7,8 @@
*
* Copyright (c) 2023 by Night-stars-1, All Rights Reserved.
*/
import path from "node:path";
const plugin_path = LiteLoader.plugins.LLAPI.path.plugin;
const ipcRenderer = LLAPI_PRE.ipcRenderer_LL;
const ipcRenderer_on = LLAPI_PRE.ipcRenderer_LL_on;
@@ -344,6 +346,7 @@ class Api extends EventEmitter {
elements.map(async (element) => {
if (element.type == "text") return destructor.destructTextElement(element);
else if (element.type == "image") return destructor.destructImageElement(element, await media.prepareImageElement(element.file));
else if (element.type == "voice") return destructor.destructPttElement(element, await media.prepareVoiceElement(element.file));
else if (element.type == "face") return destructor.destructFaceElement(element);
else if (element.type == "raw") return destructor.destructRawElement(element);
else return null;
@@ -644,6 +647,14 @@ class Destructor {
picElement: picElement,
};
}
destructPttElement(element, pttElement) {
return {
elementType: 4,
elementId: "",
pttElement
}
}
destructFaceElement(element) {
return {
@@ -811,6 +822,41 @@ class Destructor {
const destructor = new Destructor();
class Media {
async prepareVoiceElement(file) {
const type = await ntCall("ns-fsApi", "getFileType", [file]);
const md5 = await ntCall("ns-fsApi", "getFileMd5", [file]);
const fileName = `${md5}.${type.ext}`;
const filePath = await ntCall("ns-ntApi", "nodeIKernelMsgService/getRichMediaFilePath", [
{
md5HexStr: md5,
fileName: fileName,
elementType: 4,
elementSubType: 0,
thumbSize: 0,
needCreate: true,
fileType: 1, // 这个未知
},
]);
const fileSize = await ntCall("ns-fsApi", "getFileSize", [file]);
return {
canConvert2Text: true,
fileName: fileName,
filePath: filePath,
md5HexStr: md5,
fileId: 0,
fileSubId: '',
fileSize: fileSize,
duration: 2,
formatType: 1,
voiceType: 1,
voiceChangeType: 0,
playState: 1,
waveAmplitudes: [
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
],
}
}
async prepareImageElement(file) {
const type = await ntCall("ns-fsApi", "getFileType", [file]);
const md5 = await ntCall("ns-fsApi", "getFileMd5", [file]);

View File

@@ -203,7 +203,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
else if (message.type == "text"){
message.content = message.data?.text || message.content
}
else if (message.type == "image"){
else if (message.type == "image" || message.type == "voice"){
message.file = message.data?.file || message.file
}
}

View File

@@ -59,6 +59,28 @@ export type MessageElement = {
fileSize: number
fileName: string
fileUuid: string
},
pttElement: {
canConvert2Text: boolean
duration: number // 秒数
fileBizId: null
fileId: number // 0
fileName: string // "e4d09c784d5a2abcb2f9980bdc7acfe6.amr"
filePath: string // "/Users/C5366155/Library/Containers/com.tencent.qq/Data/Library/Application Support/QQ/nt_qq_a6b15c9820595d25a56c1633ce19ad40/nt_data/Ptt/2023-11/Ori/e4d09c784d5a2abcb2f9980bdc7acfe6.amr"
fileSize: string // "4261"
fileSubId: string // "0"
fileUuid: string // "90j3z7rmRphDPrdVgP9udFBaYar#oK0TWZIV"
formatType: string // 1
invalidState: number // 0
md5HexStr: string // "e4d09c784d5a2abcb2f9980bdc7acfe6"
playState: number // 0
progress: number // 0
text: string // ""
transferStatus: number // 0
translateStatus: number // 0
voiceChangeType: number // 0
voiceType: number // 0
waveAmplitudes: number[]
}
}[]
}
@@ -78,7 +100,7 @@ export type SendMessage = {
text: string, // 纯文本
}
} | {
type: "image",
type: "image" | "voice",
file: string, // 本地路径
data?: {
file: string // 本地路径

View File

@@ -3,6 +3,7 @@ const baseConfig = require('./webpack.base.config.js')
baseConfig.target = 'electron-main'
baseConfig.entry = {
main: './src/main.ts',
// preload: './src/preload.ts',
}
baseConfig.output.libraryTarget = 'commonjs2'
baseConfig.output.chunkFormat = 'commonjs'