/
bioxakep
/
VoiceTrans
Обзор
Документация
Войти
/
bioxakep
/
VoiceTrans
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
main.py
130 строк
5 KB
bioxakep
refactor
13 авг 2025, 23:54
13 авг 2025, 23:54
6aa60b3
Код
Авторство
О чём код?
import argparse import os from transcribation import smart_transcriber, TranscribeResult from utils_common import humanize_time, rename_sounds, get_phones from voice_engines import VoskRecognizer arg_parser = argparse.ArgumentParser() arg_parser.add_argument( "sounds_dir_path", type=str, help="Директория со звуковыми записями", ) arg_parser.add_argument( "-r", "--records_file_path", type=str, help="Файл со статистикой соединений", default=None, ) arg_parser.add_argument( "-t", "--tags_file_path", type=str, help="Файл с поисковыми признаками (тэгами)", default=None, ) def rename_and_transcribe( records_file_path: str, sounds_dir_path: str | None = None, tags_file_path: str | None = None, ): if not os.path.exists(records_file_path): raise FileExistsError("Файл со статистикой соединений не найден") vosk_recognizer = VoskRecognizer() if sounds_dir_path is None: sounds_dir_path = os.path.join( os.path.dirname(records_file_path), os.path.basename(records_file_path).split(".")[0], ) if not os.path.exists(sounds_dir_path): raise FileExistsError("Директория со звуком не найдена") print( "Директория со звуком определена из имени файла со статистикой соединений" ) trans_files_count = 0 total_sound_duration: int = 0 total_speech_duration: int = 0 total_trans_time: int = 0 for sound_file_path, abonent, contact, sound_dt in rename_sounds( billing_file_path=records_file_path, sounds_dir=sounds_dir_path, ): trans_result = smart_transcriber( audio_file_path=sound_file_path, recognizer=vosk_recognizer, tags_file_path=tags_file_path, abonent=abonent, contact=contact, sound_dt=sound_dt, ) if isinstance(trans_result, TranscribeResult): total_trans_time += trans_result.trans_time total_speech_duration += trans_result.speech_duration total_sound_duration += trans_result.sound_duration trans_files_count += 1 sound_duration_hum = humanize_time(total_sound_duration, clocks=False) speech_duration_hum = humanize_time(total_speech_duration, clocks=False) trans_time_hum = humanize_time(total_trans_time, clocks=False) print( f"Транскрибировано файлов: {trans_files_count}\n" f"Суммарная длительность аудиофайлов: {sound_duration_hum}\n" f"Суммарная длительность выделенной речи: {speech_duration_hum}\n" f"Общее время транскрибации: {trans_time_hum}" ) def just_transcribe( sounds_dir_path: str, tags_file_path: str | None = None, ): vosk_recognizer = VoskRecognizer() if not os.path.exists(sounds_dir_path): raise FileExistsError("Директория со звуком не найдена") trans_files_count = 0 total_sound_duration: int = 0 total_speech_duration: int = 0 total_trans_time: int = 0 for f in os.listdir(sounds_dir_path): abonent, contact = get_phones(f) file_path: str = os.path.join(sounds_dir_path, f) trans_result = smart_transcriber( audio_file_path=file_path, recognizer=vosk_recognizer, tags_file_path=tags_file_path, abonent=abonent, contact=contact, ) if isinstance(trans_result, TranscribeResult): total_trans_time += trans_result.trans_time total_speech_duration += trans_result.speech_duration total_sound_duration += trans_result.sound_duration trans_files_count += 1 sound_duration_hum = humanize_time(total_sound_duration, clocks=False) speech_duration_hum = humanize_time(total_speech_duration, clocks=False) trans_time_hum = humanize_time(total_trans_time, clocks=False) print( f"Транскрибировано файлов: {trans_files_count}\n" f"Суммарная длительность аудиофайлов: {sound_duration_hum}\n" f"Суммарная длительность выделенной речи: {speech_duration_hum}\n" f"Общее время транскрибации: {trans_time_hum}" ) if __name__ == "__main__": args = arg_parser.parse_args() if args.records_file_path: rename_and_transcribe( records_file_path=args.records_file_path, sounds_dir_path=args.sounds_dir_path, tags_file_path=args.tags_file_path, ) else: just_transcribe( sounds_dir_path=args.sounds_dir_path, tags_file_path=args.tags_file_path, )