html语音消息支持导出,如果电脑转过文字那么转的文字也可以显示出来

This commit is contained in:
STDquantum
2023-12-12 01:17:21 +08:00
parent 8e20452bbb
commit fbe1f66660
6 changed files with 88 additions and 13 deletions

View File

@@ -8,6 +8,7 @@ from PyQt5.QtWidgets import QFileDialog
from . import msg_db, micro_msg_db
from .package_msg import PackageMsg
from ..DataBase import hard_link_db
from ..DataBase import media_msg_db
from ..person_pc import MePC
from ..util import path
import shutil
@@ -220,6 +221,30 @@ class ChildThread(QThread):
f'''{str_time} {name}\n[图片]\n\n'''
)
def audio(self, doc, message):
origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}"
str_content = message[7]
str_time = message[8]
is_send = message[4]
avatar = 'myhead.png' if is_send else 'tahead.png'
timestamp = message[5]
msgSvrId = message[9]
if self.output_type == Output.HTML:
try:
audio_path = media_msg_db.get_audio(msgSvrId, output_path=origin_docx_path + "/voice")
audio_path = audio_path.replace('\\', '/')
voice_to_text = media_msg_db.get_audio_text(str_content)
except:
return
if self.is_5_min(timestamp):
doc.write(
f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:''}},'''
)
doc.write(
f'''{{ type:34, text:'{audio_path}',is_send:{is_send},avatar_path:'{avatar}',voice_to_text:'{voice_to_text}'}},'''
)
def emoji(self, doc, message):
origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}"
str_content = message[7]
@@ -381,6 +406,8 @@ class ChildThread(QThread):
self.text(f, message)
elif type_ == 3 and self.message_types.get(type_):
self.image(f, message)
elif type_ == 34 and self.message_types.get(type_):
self.audio(f, message)
elif type_ == 43 and self.message_types.get(type_):
self.video(f, message)
elif type_ == 47 and self.message_types.get(type_):
@@ -694,6 +721,12 @@ body{
margin-left: 18px;
max-width: 350px;
}
.chat-audio{
max-width: 300px;
}
audio{
right: 25px;
}
.input-area{
border-top:0.5px solid #e0e0e0;
height: 150px;
@@ -908,8 +941,8 @@ html_end = '''
else if (message.type == 49) {
if (message.sub_type == 57){
if (message.is_send == 1) {
messageElement.className = "item item-right";
messageElement.innerHTML = `<div class='chat-refer chat-refer-right'>${message.text}</div></div>`
messageElement.className = "item item-right";
messageElement.innerHTML = `<div class='chat-refer chat-refer-right'>${message.text}</div></div>`
}
else if (message.is_send == 0) {
messageElement.className = "item item-left";
@@ -917,6 +950,16 @@ html_end = '''
}
}
}
else if (message.type == 34) {
if (message.is_send == 1) {
messageElement.className = "item item-right";
messageElement.innerHTML = `<div class='chat-audio'>${message.voice_to_text == "" ? "" : `<div class="bubble">${message.voice_to_text}</div>`}<audio src="${message.text}" controls></audio></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
}
else if (message.is_send == 0) {
messageElement.className = "item item-left";
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='chat-audio'>${message.voice_to_text == "" ? "" : `<div class="bubble">${message.voice_to_text}</div>`}<audio src="${message.text}" controls></audio></div>`
}
}
chatContainer.appendChild(messageElement);
}
document.querySelector("#chat-container").scrollTop = 0;