|
import replicate |
|
import httpx |
|
|
|
|
|
def transcribe_audio(audio_file): |
|
|
|
audio = AudioSegment.from_file(audio_file) |
|
audio_duration_minutes = len(audio) / (1000 * 60) |
|
|
|
|
|
if audio_duration_minutes > 10: |
|
segments = dividir_audio(audio_file, segment_duration_ms=10 * 60 * 1000) |
|
else: |
|
segments = [audio_file] |
|
|
|
|
|
all_transcriptions = [] |
|
|
|
|
|
for segment_path in segments: |
|
with open(segment_path, "rb") as audio: |
|
|
|
with httpx.Client(timeout=300) as client: |
|
output = replicate.run( |
|
"vaibhavs10/incredibly-fast-whisper:3ab86df6c8f54c11309d4d1f930ac292bad43ace52d10c80d87eb258b3c9f79c", |
|
input={ |
|
"task": "transcribe", |
|
"audio": audio, |
|
"language": "None", |
|
"timestamp": "chunk", |
|
"batch_size": 64, |
|
"diarise_audio": False |
|
}, |
|
client=client |
|
) |
|
|
|
all_transcriptions.append(output['text']) |
|
|
|
|
|
full_transcription = "\n".join(all_transcriptions) |
|
return full_transcription |
|
|