This commit is contained in:
HuangHai
2026-01-20 21:43:54 +08:00
parent 66cb0faeff
commit 55e88777d9
32 changed files with 1112 additions and 60 deletions

View File

@@ -1,18 +1,18 @@
import os
import asyncio
import logging
import sys
import time
# Ensure project root is in path
sys.path.append(r"d:\dsWork\aiData")
from Util.ASRClient import ASRClient
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', stream=sys.stdout)
logger = logging.getLogger("Transcriber")
async def transcribe_all():
def transcribe_all():
audio_dir = r"d:\dsWork\aiData\DouYin\Audios"
transcript_dir = r"d:\dsWork\aiData\DouYin\Transcripts"
@@ -22,6 +22,8 @@ async def transcribe_all():
client = ASRClient()
files = [f for f in os.listdir(audio_dir) if f.endswith(".mp3")]
# Sort files to ensure deterministic order
files.sort()
logger.info(f"Found {len(files)} audio files.")
for filename in files:
@@ -41,8 +43,8 @@ async def transcribe_all():
logger.info(f"Processing: {filename}")
try:
# Direct local file transcription using Recognition API
text = await client.transcribe_file(audio_path)
# Direct local file transcription using synchronous method
text = client.transcribe_file_sync(audio_path)
if text:
with open(txt_path, 'w', encoding='utf-8') as f:
@@ -50,13 +52,16 @@ async def transcribe_all():
logger.info(f"Saved transcript to: {txt_filename}")
else:
logger.error(f"Failed to transcribe: {filename}")
# Add a small delay between files
time.sleep(1)
except Exception as e:
logger.error(f"Error processing {filename}: {str(e)}", exc_info=True)
if __name__ == "__main__":
try:
asyncio.run(transcribe_all())
transcribe_all()
except KeyboardInterrupt:
logger.info("Stopped by user")
except Exception as e: