Я видел в других сообщениях и блогах, что производительность Whisper становится все хуже и хуже, когда звук длиннее, поэтому я разделил звук на сегменты по 15 минут с помощью pydub в следующем коде:
Код: Выделить всё
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"]
- Мне удается полностью расшифровать звук с помощью других больших моделей с сегментами по 15 минут.
- Мне удается полностью расшифровать звук с помощью модели big-v3 только тогда, когда аудиосегменты длятся менее 5 минут (4,9 минуты — это нормально, а 5 — нет)
- Я уже проверил, все ли мои сегментированные аудиофайлы были расшифрованы, и все они
Подробнее здесь: https://stackoverflow.com/questions/798 ... e-my-audio
Мобильная версия