mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
feat(sample): add transcription of sample file (#1973)
This commit is contained in:
1 parent
5a361407a8
commit
09141d04e9
3 files changed
+51
-11
No files matched your search
@@ -1,5 +1,9 @@
|
||||
# CHANGELOG
|
||||
|
||||
## Next
|
||||
|
||||
- feat(sample): add transcription of sample file
|
||||
|
||||
## Version 4.0.3 (2025-12-07)
|
||||
|
||||
- feat(cli): add `--revision` option to most CLI commands
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2024- CNRS
|
||||
# Copyright (c) 2024-2025 CNRS
|
||||
# Copyright (c) 2026- pyannoteAI
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -23,34 +24,56 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from pyannote.audio.core.io import Audio, AudioFile
|
||||
from pyannote.core import Annotation, Segment, Timeline
|
||||
from pyannote.database.util import load_rttm
|
||||
|
||||
from pyannote.audio.core.io import Audio, AudioFile
|
||||
|
||||
def load_stm(file_stm: str | Path) -> dict[str, list[dict]]:
|
||||
session_ids = {}
|
||||
|
||||
with open(file_stm, "r") as stm:
|
||||
for line in stm:
|
||||
infos = line.strip().split()
|
||||
session_id, _, spk, start, end, *words = infos
|
||||
|
||||
entry = {
|
||||
"start": float(start),
|
||||
"end": float(end),
|
||||
"text": " ".join(words),
|
||||
"speaker": spk,
|
||||
}
|
||||
|
||||
session_ids.setdefault(session_id, []).append(entry)
|
||||
|
||||
return session_ids
|
||||
|
||||
|
||||
def _sample() -> AudioFile:
|
||||
sample_wav = Path(__file__).parent / "sample.wav"
|
||||
uri = "sample"
|
||||
def _sample(uri: str = "sample") -> AudioFile:
|
||||
sample_wav = Path(__file__).parent / f"{uri}.wav"
|
||||
|
||||
audio = Audio()
|
||||
waveform, sample_rate = audio(sample_wav)
|
||||
|
||||
sample_rttm = Path(__file__).parent / "sample.rttm"
|
||||
|
||||
annotation: Annotation = load_rttm(sample_rttm)[uri]
|
||||
sample_rttm = Path(__file__).parent / f"{uri}.rttm"
|
||||
diarization: Annotation = load_rttm(sample_rttm)[uri]
|
||||
duration = audio.get_duration(sample_wav)
|
||||
|
||||
annotated: Timeline = Timeline([Segment(0.0, duration)], uri=uri)
|
||||
|
||||
sample_stm = Path(__file__).parent / f"{uri}.stm"
|
||||
transcription = load_stm(sample_stm)[uri]
|
||||
|
||||
return {
|
||||
"audio": sample_wav,
|
||||
"uri": "sample",
|
||||
"uri": uri,
|
||||
"waveform": waveform,
|
||||
"sample_rate": sample_rate,
|
||||
"annotation": annotation,
|
||||
"annotation": diarization,
|
||||
"annotated": annotated,
|
||||
"diarization": diarization,
|
||||
"transcription": transcription,
|
||||
}
|
||||
|
||||
|
||||
SAMPLE_FILE = _sample()
|
||||
SAMPLE_FILE = _sample(uri="sample")
|
||||
@@ -0,0 +1,13 @@
|
||||
sample 1 Diane 6.68 7.16 Hello?
|
||||
sample 1 Sheila 7.634 8.155 Hello?
|
||||
sample 1 Diane 8.436 8.876 Oh, hello.
|
||||
sample 1 Diane 8.916 9.798 I didn't know you were there.
|
||||
sample 1 Sheila 9.838 10.78 Neither did I.
|
||||
sample 1 Diane 10.78 12.54 Okay, then I thought you know, I heard a beep.
|
||||
sample 1 Diane 12.542 14.184 This is Diane in New Jersey.
|
||||
sample 1 Sheila 14.444 17.769 And I'm Sheila in Texas, originally from Chicago.
|
||||
sample 1 Diane 17.789 20.113 Oh, I'm originally from Chicago also.
|
||||
sample 1 Diane 20.173 21.475 I'm in New Jersey now though.
|
||||
sample 1 Sheila 21.935 23.978 Well, there isn't that much difference.
|
||||
sample 1 Sheila 24.058 28.425 At least you know, they all call me a Yankee down here, so what can I say?
|
||||
sample 1 Diane 28.445 29.987 Oh, I don't hear that in New Jersey now.
|
||||
Reference in new issue
Block a user