in function_app/src/components/speech.py [0:0]
def process_fast_transcription(transcription: Dict) -> Transcription:
"""
Processes a transcription response from the Azure AI Speech Fast
Transcription API.
:param transcription: The raw API response from Azure AI Speech API.
:type transcription: Dict
:return: A processed Transcription object.
:rtype: Transcription
"""
word_count = 0
# Phrases come sorted by channel -> offset. Sort by offset alone
raw_phrases = sorted(transcription["phrases"], key=lambda phrase: phrase["offset"])
processed_phrases: list[TranscribedPhrase] = list()
for phrase_num, raw_phrase in enumerate(raw_phrases):
raw_words = raw_phrase["words"]
processed_words = [
process_fast_word_dict(raw_word, word_count + i)
for i, raw_word in enumerate(raw_words)
]
word_count += len(raw_words)
processed_phrases.append(
process_fast_phrase_dict(raw_phrase, phrase_num, processed_words)
)
return Transcription(
phrases=processed_phrases,
transcription_type=AzureSpeechTranscriptionEnum.FAST,
duration_secs=round(
transcription["duration"]
/ TIME_DIVISORS[AzureSpeechTranscriptionEnum.FAST],
3,
),
language=None,
raw_api_response=transcription,
)