Ver Fonte

revert whisper.cpp

subDesTagesMitExtraKaese há 2 anos atrás
pai
commit
19d53a729b
4 ficheiros alterados com 15 adições e 24 exclusões
  1. 5 17
      Dockerfile
  2. 1 1
      README.md
  3. 8 4
      main.py
  4. 1 2
      requirements.txt

+ 5 - 17
Dockerfile

@@ -1,33 +1,21 @@
-# build image
-FROM debian:bullseye-slim AS builder
-WORKDIR /build/
-RUN apt-get update && apt-get install --no-install-recommends -y \
-    make gcc g++ wget \
- && apt-get clean \
- && rm -rf /var/lib/apt/lists/*
-
-# Install Whisper.cpp
-ADD whisper.cpp/ /build/
-RUN make
-
 # main image
-FROM python:3.9-slim-bullseye
+FROM python:3.9-bullseye
 WORKDIR /app/
 
 # Install dependencies
 RUN apt-get update && apt-get install -y \
-    ffmpeg libolm-dev gcc make wget\
+    ffmpeg libolm-de \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*
 
+# Install Whisper
+RUN pip install git+https://github.com/openai/whisper.git
+
 ADD requirements.txt .
 
 RUN pip install -r requirements.txt && \
-  apt-get remove -y gcc make && \
   apt-get autoremove -y
 
-COPY --from=builder /build/main /app/
-
 VOLUME /data/
 
 ADD ./*.py /app/

+ 1 - 1
README.md

@@ -23,7 +23,7 @@ services:
       - "USERNAME=@stt-bot:example.com"
       - "PASSWORD=<password>"
       - "ASR_MODEL=tiny"
-      - "ASR_LANGUAGE=en"
+      - "XDG_CACHE_HOME=/data/cache"
 ```
 
 ## Configuration

+ 8 - 4
main.py

@@ -1,11 +1,12 @@
 #!/usr/bin/env python3
+import tempfile
 from urllib.parse import urlparse
 import os
 
 import simplematrixbotlib as botlib
 import nio
 
-from speech_recognition import ASR
+import whisper
 
 creds = botlib.Creds(
   homeserver=os.environ['HOMESERVER'],
@@ -23,7 +24,7 @@ config.ignore_unverified_devices = True
 config.store_path = '/data/crypto_store/'
 bot = botlib.Bot(creds, config)
 
-asr = ASR(os.getenv('ASR_MODEL', 'tiny'), os.getenv('ASR_LANGUAGE', 'en'))
+model = whisper.load_model(os.getenv('ASR_MODEL', 'tiny'))
 
 @bot.listener.on_custom_event(nio.RoomMessage)
 async def on_message(room, event):
@@ -54,8 +55,12 @@ async def on_message(room, event):
       data = response.body
 
     print(response)
-    result = await asr.transcribe(data)
 
+    with tempfile.NamedTemporaryFile("w+b") as file:
+      file.write(data)
+      file.flush()
+      print(file.name)
+      result = model.transcribe(file.name)['text']
     await bot.async_client.room_typing(room.machine_name, False)
 
     if not result:
@@ -81,5 +86,4 @@ async def on_message(room, event):
       })
 
 if __name__ == "__main__":
-  asr.load_model()
   bot.run()

+ 1 - 2
requirements.txt

@@ -1,3 +1,2 @@
 simplematrixbotlib==2.7.0
-matrix-nio[e2e]==0.19
-ffmpeg-python
+matrix-nio[e2e]==0.19