-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscribe.py
executable file
·46 lines (30 loc) · 1.04 KB
/
transcribe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!python3
from datetime import datetime
import typer
from loguru import logger
from rich import print
from pathlib import Path
import assemblyai as aai
from icecream import ic
import os
app = typer.Typer(no_args_is_help=True)
@app.command()
def transcribe(
path: Path = typer.Argument(None), diarization: bool = True, srt: bool = False
):
aai.settings.api_key = os.environ.get("ASSEMBLYAI_API_KEY")
default_audio_url = "https://github.com/AssemblyAI-Community/audio-examples/raw/main/20230607_me_canadian_wildfires.mp3"
audio_url = path.open("rb") if path else default_audio_url
config = aai.TranscriptionConfig(speaker_labels=diarization)
ic(audio_url, datetime.now())
transcript = aai.Transcriber().transcribe(audio_url, config)
ic(transcript)
for utterance in transcript.utterances:
print(f"Speaker {utterance.speaker}: {utterance.text}")
if srt:
print(transcript.export_subtitles_srt())
@logger.catch()
def app_wrap_loguru():
app()
if __name__ == "__main__":
app_wrap_loguru()