50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
异步音视频转写使用示例
|
|
"""
|
|
|
|
# 配置示例
|
|
config = {
|
|
'async_processing': True, # 启用异步处理
|
|
'worker_count': 2, # 工作线程数量
|
|
'queue_size': 10, # 队列大小
|
|
}
|
|
|
|
# 使用示例
|
|
from apps.common.handle.impl.media.media_adapter.processors.audio_processor import AudioProcessor
|
|
|
|
# 创建处理器
|
|
processor = AudioProcessor(config, logger)
|
|
|
|
# 处理选项
|
|
options = {
|
|
'async_processing': True, # 启用异步模式
|
|
'enable_punctuation': True, # 启用标点符号优化
|
|
'enable_summary': True, # 启用摘要生成
|
|
'segment_duration': 300, # 5分钟分段
|
|
'language': 'auto' # 自动检测语言
|
|
}
|
|
|
|
# 处理音频文件
|
|
result = processor.process(
|
|
file_content=audio_bytes,
|
|
file_name="audio.mp3",
|
|
stt_model=stt_model,
|
|
llm_model=llm_model,
|
|
options=options
|
|
)
|
|
|
|
# 结果示例
|
|
print(f"处理状态: {result['status']}")
|
|
print(f"音频时长: {result['duration']:.1f}秒")
|
|
print(f"分段数量: {len(result['segments'])}")
|
|
print(f"处理时间: {result['metadata']['processing_time']:.2f}秒")
|
|
|
|
# 查看每个分段的结果
|
|
for segment in result['segments']:
|
|
print(f"分段 {segment['index']}: {segment['start_time']:.1f}s - {segment['end_time']:.1f}s")
|
|
print(f"转写文本: {segment['text']}")
|
|
print(f"增强文本: {segment['enhanced_text']}")
|
|
if segment.get('summary'):
|
|
print(f"摘要: {segment['summary']}")
|
|
print("---") |