Ich habe in anderen Beiträgen und Blogs gesehen, dass die Whisper-Leistung immer schlechter wird, wenn der Ton länger ist, also habe ich den Ton mit pydub im folgenden Code in Segmente von 15 Minuten aufgeteilt:
Code: Select all
from pydub import AudioSegment
def segment_audio_duration(audio_file: str, millisecond_duration: int, output_folder, format: str) -> tuple[int, str]:
"""
segment the audio into segments during _millisecond_duration_ and directly export them to _output_folder_
returns a tuple containg the number of segment created and the name of a file without the number
"""
sound = AudioSegment.from_file(audio_file)
duration = len(sound)
num_chunks = math.ceil(duration / millisecond_duration)
basename = audio_file.split(os.sep)[-1]
filename = basename.split('.')[0]
ext = basename.split('.')[-1]
for i in range(num_chunks):
temp = sound[i * millisecond_duration:(i+1) * millisecond_duration]
temp.export(f"{output_folder}{os.sep}{filename}_part{i+1}.{format}", format=format)
return (num_chunks, f"{filename}_part")
def transcript_audio(audio_path: str, model, language: str = "fr", gpu_usable: bool = False) -> str:
"""
Simple auxiliary function to _get_transcription_ function
:param audio_path: path of the audi file
:type audio_path: str
:param model: used model to transcribe
:param language: language of the audio
:type language: str
:return: raw content transcription
:rtype: str
"""
try:
result = model.transcribe(
audio_path,
temperature=0.0,
language=language,
fp16=gpu_usable
)
except Exception as e:
raise Exception(f"Unable to retrieve the transcription of {audio_path} ({e})")
return result["text"]
- Es gelingt mir, Audio mit den anderen großen Modellen mit Segmenten von 15 Minuten vollständig zu transkribieren
- Es gelingt mir nur, Audio mit dem großen v3-Modell vollständig zu transkribieren, wenn Audiosegmente weniger als 5 Minuten dauern (4,9 Minuten sind in Ordnung, aber 5 nicht).
- Ich habe bereits überprüft, ob alle meine segmentierte Audiodateien wurden transkribiert und sie sind alle
Mobile version