feat: checking file mime type before sending it to Whisper
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
maubot: 0.1.0
|
||||
id: nigzu.com.maubot-stt
|
||||
version: 0.3.0
|
||||
version: 0.3.1
|
||||
license: MIT
|
||||
modules:
|
||||
- openai-whisper
|
||||
|
||||
BIN
nigzu.com.maubot-stt-v0.3.0.mbp
Normal file
BIN
nigzu.com.maubot-stt-v0.3.0.mbp
Normal file
Binary file not shown.
@@ -12,6 +12,9 @@ from mautrix.errors import MatrixRequestError
|
||||
from mautrix.types import EventType, MessageType, RelationType, TextMessageEventContent, Format,RelatesTo,InReplyTo
|
||||
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
|
||||
|
||||
ALLOWED_EXTENSIONS = ['flac', 'm4a', 'mp3', 'mp4', 'mpeg', 'mpga', 'oga', 'ogg', 'wav', 'webm']
|
||||
ALLOWED_MIME_TYPES = ['audio/flac','audio/mp4','video/mpeg','audio/ogg','audio/wav','video/webm']
|
||||
|
||||
class Config(BaseProxyConfig):
|
||||
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
||||
helper.copy("whisper_endpoint")
|
||||
@@ -45,6 +48,9 @@ class WhisperPlugin(Plugin):
|
||||
|
||||
if self.allowed_rooms and event.room_id not in self.allowed_rooms:
|
||||
return False
|
||||
|
||||
if event.content.info.mimetype not in ALLOWED_MIME_TYPES:
|
||||
return False
|
||||
|
||||
return event.content.msgtype == MessageType.AUDIO or event.content.msgtype == MessageType.FILE
|
||||
|
||||
@@ -56,8 +62,6 @@ class WhisperPlugin(Plugin):
|
||||
try:
|
||||
await event.mark_read()
|
||||
await self.client.set_typing(event.room_id, timeout=99999)
|
||||
|
||||
self.log.error(event)
|
||||
|
||||
audio_bytes = await self.client.download_media(url=event.content.url)
|
||||
transcription = await self.transcribe_audio(audio_bytes)
|
||||
|
||||
Reference in New Issue
Block a user