feat: add model/MODEL_NAME parameters
Some checks failed
Python tests / tests (push) Failing after 8s
Some checks failed
Python tests / tests (push) Failing after 8s
in order to allow for better efficiency and consistency
This commit is contained in:
10
main.py
10
main.py
@@ -12,10 +12,10 @@ from selenium.webdriver.common.by import By
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from settings import DOCUMENT_ID, WEBHOOK_URL
|
from settings import DOCUMENT_ID, WEBHOOK_URL, MODEL_NAME
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("settings.py nicht gefunden, verwende settings_example.py")
|
print("settings.py nicht gefunden, verwende settings_example.py")
|
||||||
from settings_example import DOCUMENT_ID, WEBHOOK_URL
|
from settings_example import DOCUMENT_ID, WEBHOOK_URL, MODEL_NAME
|
||||||
|
|
||||||
from transcription import transcribe_audio_with_whisper
|
from transcription import transcribe_audio_with_whisper
|
||||||
|
|
||||||
@@ -146,13 +146,17 @@ def test_transcription():
|
|||||||
accuracy = 0
|
accuracy = 0
|
||||||
total = 0
|
total = 0
|
||||||
|
|
||||||
|
# Load Whisper model once for efficiency
|
||||||
|
import whisper
|
||||||
|
model = whisper.load_model(MODEL_NAME)
|
||||||
|
|
||||||
# create or overwrite CSV file for transcription results
|
# create or overwrite CSV file for transcription results
|
||||||
with open("transcription_results.csv", "w") as csvfile:
|
with open("transcription_results.csv", "w") as csvfile:
|
||||||
csvfile.write("filename,transcription\n")
|
csvfile.write("filename,transcription\n")
|
||||||
|
|
||||||
for mp3_path in download_dir.glob("*.mp3"):
|
for mp3_path in download_dir.glob("*.mp3"):
|
||||||
print(f"Verarbeite Datei: {mp3_path}")
|
print(f"Verarbeite Datei: {mp3_path}")
|
||||||
transcription = transcribe_audio_with_whisper(mp3_path)
|
transcription = transcribe_audio_with_whisper(mp3_path, model=model)
|
||||||
|
|
||||||
print(f"Transkription: {transcription}")
|
print(f"Transkription: {transcription}")
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
try:
|
||||||
|
from settings import MODEL_NAME
|
||||||
|
except ImportError:
|
||||||
|
print("settings.py nicht gefunden, verwende settings_example.py")
|
||||||
|
from settings_example import MODEL_NAME
|
||||||
|
|
||||||
# Mapping von gesprochenen Buchstaben (deutsch) auf Zeichen
|
# Mapping von gesprochenen Buchstaben (deutsch) auf Zeichen
|
||||||
SPOKEN_TO_CHAR = {
|
SPOKEN_TO_CHAR = {
|
||||||
"a": "a", "ah": "a",
|
"a": "a", "ah": "a",
|
||||||
@@ -60,9 +66,11 @@ def _normalize_transcription(raw_text):
|
|||||||
print(f"Unbekanntes Token: '{token}'")
|
print(f"Unbekanntes Token: '{token}'")
|
||||||
return ''.join(result)
|
return ''.join(result)
|
||||||
|
|
||||||
def transcribe_audio_with_whisper(mp3_path):
|
def transcribe_audio_with_whisper(mp3_path, model=None):
|
||||||
import whisper
|
if model is None:
|
||||||
model = whisper.load_model("small")
|
import whisper
|
||||||
|
model = whisper.load_model(MODEL_NAME)
|
||||||
|
|
||||||
result = model.transcribe(str(mp3_path), language='de')
|
result = model.transcribe(str(mp3_path), language='de')
|
||||||
raw_text = result["text"]
|
raw_text = result["text"]
|
||||||
print("Raw transcription:", raw_text)
|
print("Raw transcription:", raw_text)
|
||||||
|
|||||||
Reference in New Issue
Block a user