add multiple audiofiles input and glue it
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
from pathlib import Path
|
||||
from markdown_pdf import MarkdownPdf # Для аннотации типов
|
||||
|
||||
# Для аннотации типов
|
||||
from markdown_pdf import MarkdownPdf
|
||||
from pydub import AudioSegment
|
||||
|
||||
class FileHandlers:
|
||||
# Функция сохранения файла
|
||||
def saveFile(self, filename, content, output_path):
|
||||
def saveFile(self, filename, content, output_path, format='mp3'):
|
||||
'''
|
||||
Сохраняет текст или pdf из markdown_pdf в файл с указанным названием и директорией.
|
||||
Сохраняет текст, pdf из markdown_pdf или склеенный аудиофайл в файл с указанным названием и директорией.
|
||||
|
||||
Args:
|
||||
:param filename: название файла;
|
||||
@@ -16,8 +19,13 @@ class FileHandlers:
|
||||
directory = Path(output_path)
|
||||
filePath = directory / filename # Добавление пути директории
|
||||
filePath.parent.mkdir(parents=True, exist_ok=True) # Создание директории если не существует
|
||||
|
||||
# Сохранение для разных типов
|
||||
if type(content) == MarkdownPdf:
|
||||
content.save(filePath)
|
||||
return content.save(filePath)
|
||||
|
||||
elif type(content) == str:
|
||||
filePath.write_text(content, encoding='utf-8')
|
||||
return filePath.write_text(content, encoding='utf-8')
|
||||
|
||||
elif type(content) == AudioSegment:
|
||||
return content.export(filePath, format=format)
|
||||
|
||||
11
handlers/glueAudio.py
Normal file
11
handlers/glueAudio.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from pydub import AudioSegment
|
||||
|
||||
class GlueAudio():
|
||||
def glue(self, audioFiles):
|
||||
glued = AudioSegment.empty()
|
||||
|
||||
for audioFile in audioFiles:
|
||||
audio = AudioSegment.from_file(audioFile)
|
||||
glued += audio
|
||||
|
||||
return glued
|
||||
@@ -1,12 +1,19 @@
|
||||
class GradioHandlers:
|
||||
def __init__(self, gr, Llm, ConvertMdToPdf, FileHandlers, FasterWhisper):
|
||||
def __init__(self, gr, Llm, ConvertMdToPdf, FileHandlers, FasterWhisper, GlueAudio):
|
||||
# Объект для работы с файлами
|
||||
self.fh = FileHandlers()
|
||||
self.ga = GlueAudio()
|
||||
self.ConvertMdToPdf = ConvertMdToPdf()
|
||||
self.FasterWhisper = FasterWhisper()
|
||||
self.Llm = Llm
|
||||
self.gr = gr
|
||||
|
||||
def handleRecognizeBtn(self, audioFiles, model, device, compute_type, beamSize, vadFilter, minSilenceDurationMs, speechPadMs, temp0, temp1, temp2, wordTimestamps, noSpeechThreshold, conditionOnPreviousText, filename, outPath):
|
||||
audioFile = self.ga.glue(audioFiles)
|
||||
file = self.fh.saveFile(filename, audioFile, outPath)
|
||||
|
||||
return self.FasterWhisper.recognize(model, device, compute_type, file, beamSize, vadFilter, minSilenceDurationMs, speechPadMs, temp0, temp1, temp2, wordTimestamps, noSpeechThreshold, conditionOnPreviousText)
|
||||
|
||||
# Функция улучшения текста
|
||||
def generateByCondition(self, api_key, llm_model, system_prompt, recognized_text, llm_temperature, is_pipeline_enabled, trigger, isSaveFile, filename, filenamePdf, output_path):
|
||||
llm = self.Llm(api_key)
|
||||
|
||||
Reference in New Issue
Block a user