|
@@ -28,21 +28,36 @@ def convert_audio(data: bytes, out_filename: str):
|
|
|
return out
|
|
|
|
|
|
MODELS = [
|
|
|
- "tiny.en",
|
|
|
- "tiny.en-q5_1",
|
|
|
- "tiny",
|
|
|
- "tiny-q5_1",
|
|
|
- "base.en",
|
|
|
- "base.en-q5_1",
|
|
|
- "base",
|
|
|
- "base-q5_1",
|
|
|
- "small.en",
|
|
|
- "small.en-q5_1",
|
|
|
- "small",
|
|
|
+ "tiny",
|
|
|
+ "tiny.en",
|
|
|
+ "tiny-q5_1",
|
|
|
+ "tiny.en-q5_1",
|
|
|
+ "tiny-q8_0",
|
|
|
+ "base",
|
|
|
+ "base.en",
|
|
|
+ "base-q5_1",
|
|
|
+ "base.en-q5_1",
|
|
|
+ "base-q8_0",
|
|
|
+ "small",
|
|
|
+ "small.en",
|
|
|
+ "small.en-tdrz",
|
|
|
"small-q5_1",
|
|
|
- "medium.en-q5_0",
|
|
|
- "medium-q5_0",
|
|
|
- "large-q5_0"
|
|
|
+ "small.en-q5_1",
|
|
|
+ "small-q8_0",
|
|
|
+ "medium",
|
|
|
+ "medium.en",
|
|
|
+ "medium-q5_0",
|
|
|
+ "medium.en-q5_0",
|
|
|
+ "medium-q8_0",
|
|
|
+ "large-v1",
|
|
|
+ "large-v2",
|
|
|
+ "large-v2-q5_0",
|
|
|
+ "large-v2-q8_0",
|
|
|
+ "large-v3",
|
|
|
+ "large-v3-q5_0",
|
|
|
+ "large-v3-turbo",
|
|
|
+ "large-v3-turbo-q5_0",
|
|
|
+ "large-v3-turbo-q8_0",
|
|
|
]
|
|
|
|
|
|
class ASR():
|
|
@@ -52,20 +67,20 @@ class ASR():
|
|
|
self.model = model
|
|
|
self.language = language
|
|
|
|
|
|
- if os.path.exists(f"/app/ggml-model-whisper-{model}.bin"):
|
|
|
- self.model_path = f"/app/ggml-model-whisper-{model}.bin"
|
|
|
+ if os.path.exists(f"/app/ggml-{model}.bin"):
|
|
|
+ self.model_path = f"/app"
|
|
|
else:
|
|
|
- self.model_path = f"/data/models/ggml-{model}.bin"
|
|
|
- if not os.path.exists("/data/models"):
|
|
|
- os.mkdir("/data/models")
|
|
|
-
|
|
|
- self.model_url = f"https://ggml.ggerganov.com/ggml-model-whisper-{self.model}.bin"
|
|
|
+ self.model_path = f"/data/models"
|
|
|
+ if not os.path.exists(self.model_path):
|
|
|
+ os.mkdir(self.model_path)
|
|
|
+
|
|
|
self.lock = asyncio.Lock()
|
|
|
|
|
|
def load_model(self):
|
|
|
- if not os.path.exists(self.model_path) or os.path.getsize(self.model_path) == 0:
|
|
|
+ file_path = f"{self.model_path}/ggml-{self.model}.bin"
|
|
|
+ if not os.path.exists(file_path) or os.path.getsize(file_path) == 0:
|
|
|
print("Downloading model...")
|
|
|
- subprocess.run(["wget", "-nv", self.model_url, "-O", self.model_path], check=True)
|
|
|
+ subprocess.run(["./download-ggml-model.sh", self.model, self.model_path], check=True)
|
|
|
print("Done.")
|
|
|
|
|
|
async def transcribe(self, audio: bytes) -> str:
|
|
@@ -74,7 +89,7 @@ class ASR():
|
|
|
async with self.lock:
|
|
|
proc = await asyncio.create_subprocess_exec(
|
|
|
"./main",
|
|
|
- "-m", self.model_path,
|
|
|
+ "-m", f"{self.model_path}/ggml-{self.model}.bin",
|
|
|
"-l", self.language,
|
|
|
"-f", filename,
|
|
|
"-nt",
|