fix log issue
This commit is contained in:
@@ -35,7 +35,8 @@ def transcribe_audio_funasr(audio_path, device="cuda:0"):
|
||||
remote_code="./model.py", # Make sure this file is accessible
|
||||
vad_model="fsmn-vad",
|
||||
vad_kwargs={"max_single_segment_time": 30000},
|
||||
device=device
|
||||
device=device,
|
||||
disable_update=True
|
||||
)
|
||||
|
||||
logger.info("📤 Transcribing with FunASR...")
|
||||
@@ -52,26 +53,45 @@ def transcribe_audio_funasr(audio_path, device="cuda:0"):
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
return text
|
||||
|
||||
def transcribe_audio_funasr_batch(audio_path):
|
||||
model = AutoModel(model="iic/SenseVoiceSmall", trust_remote_code=True, device="cuda:0", disable_update=True)
|
||||
|
||||
def convert_media(file_path):
|
||||
res = model.generate(
|
||||
input=audio_path,
|
||||
cache={},
|
||||
language="auto", # "zh", "en", "yue", "ja", "ko", "nospeech"
|
||||
use_itn=True,
|
||||
batch_size=64,
|
||||
)
|
||||
|
||||
text = rich_transcription_postprocess(res[0]["text"])
|
||||
return text
|
||||
|
||||
|
||||
def convert_media(file_path, is_batch=False, save_to_disk=True):
|
||||
try:
|
||||
audio_file = extract_or_convert_audio(file_path)
|
||||
transcript = transcribe_audio_funasr(audio_file)
|
||||
if is_batch:
|
||||
transcript = transcribe_audio_funasr_batch(audio_file)
|
||||
else:
|
||||
transcript = transcribe_audio_funasr(audio_file)
|
||||
logger.info("\n📜 Transcript:")
|
||||
logger.info(transcript)
|
||||
|
||||
# ✅ Save transcript to disk
|
||||
output_path = os.path.splitext(file_path)[0] + "_transcript.md"
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
f.write(transcript)
|
||||
|
||||
logger.info(f"✅ Transcript saved to: {output_path}")
|
||||
if save_to_disk:
|
||||
output_path = os.path.splitext(file_path)[0] + ".md"
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
f.write(transcript)
|
||||
logger.info(f"✅ Transcript saved to: {output_path}")
|
||||
return transcript
|
||||
finally:
|
||||
if os.path.exists("processed_audio.wav"):
|
||||
os.remove("processed_audio.wav")
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
audio_files = []
|
||||
for root, dirs, files in os.walk('media'):
|
||||
|
||||
Reference in New Issue
Block a user