subDesTagesMitExtraKaese 2 anni fa
parent
commit
a071ae1011
3 ha cambiato i file con 24 aggiunte e 17 eliminazioni
  1. 21 14
      Dockerfile
  2. 2 1
      requirements.txt
  3. 1 2
      speech_recognition.py

+ 21 - 14
Dockerfile

@@ -1,27 +1,34 @@
-FROM python:3-bullseye-slim
+# 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 gcc -pthread -O3 -march=native -c ggml.c && \
+    g++ -pthread -O3 -std=c++11 -c main.cpp && \
+    g++ -pthread -o main ggml.o main.o && \
+    ./download-ggml-model.sh tiny
+
+# main image
+FROM alpine
 WORKDIR /app/
 
 # Install dependencies
-RUN apt-get update && apt-get install -y \
-    ffmpeg libolm-dev \
- && apt-get clean \
- && rm -rf /var/lib/apt/lists/*
+RUN apk add ffmpeg py3-olm py3-matrix-nio py3-pip py3-pillow
 
 ADD requirements.txt .
 
 RUN pip install -r requirements.txt
 
-# Install Whisper
-ADD whisper.cpp/ .
-RUN cd whisper.cpp && \
-    make tiny && \
-    cp main ../whisper && \
-    cp models/ .. && \
-    cd .. && \
-    rm -rf whisper.cpp/
+COPY --from=builder /build/main /app/
+COPY --from=builder /build/models/ /app/models/
 
 VOLUME /data/
 
 ADD . /app/
 
-CMD ["python", "-u", "main.py"]
+CMD ["python3", "-u", "main.py"]

+ 2 - 1
requirements.txt

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

+ 1 - 2
speech_recognition.py

@@ -1,7 +1,6 @@
 import ffmpeg
 import subprocess
 import tempfile
-import numpy as np
 
 SAMPLE_RATE = 16000
 
@@ -29,7 +28,7 @@ class ASR():
       file.write(audio)
       file.flush()
       stdout, stderr = subprocess.Popen(
-          ["./whisper", "-m", f"models/ggml-{self.model}.bin", "-f", file.name], 
+          ["./main", "-m", f"models/ggml-{self.model}.bin", "-f", file.name], 
           stdout=subprocess.PIPE
         ).communicate()
       if stderr: