Skip to content

Fails on empty transcription with IndexError: list index out of range #15

@ddorian

Description

@ddorian

What's happening that seems wrong?

It raises an IndexError.

Steps to reproduce

import deepgram_captions

mm = {
    "metadata": {
        "transaction_key": "deprecated",
        "request_id": "1ddf6fb2-703a-4d22-b4be-2d1c2eac1c02",
        "sha256": "c3595443b4c3b0950919e613f065983c5d5d8538ee2565ec985a990e8eef8d53",
        "created": "2024-07-03T10:15:54.608Z",
        "duration": 5.02,
        "channels": 1,
        "models": ["30089e05-99d1-4376-b32e-c263170674af"],
        "model_info": {
            "30089e05-99d1-4376-b32e-c263170674af": {
                "name": "2-general-nova",
                "version": "2024-01-09.29447",
                "arch": "nova-2",
            }
        },
    },
    "results": {
        "channels": [
            {
                "alternatives": [
                    {
                        "transcript": "",
                        "confidence": 0.0,
                        "words": [],
                        "paragraphs": {"transcript": "\n", "paragraphs": []},
                    }
                ],
                "detected_language": "en",
                "language_confidence": 0.15507619,
            }
        ]
    },
}

transcription = deepgram_captions.DeepgramConverter(mm)
print(transcription.response)
captions_text = deepgram_captions.webvtt(transcription)
Traceback (most recent call last):
  File "/home/mymymy.py", line 40, in <module>
    captions_text = deepgram_captions.webvtt(transcription)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.venv/lib/python3.12/site-packages/deepgram_captions/webvtt.py", line 25, in webvtt
    speaker_labels = "speaker" in lines[0][0]
                                  ~~~~~~~~^^^
IndexError: list index out of range

To make it faster to diagnose the root problem. Tell us how can we reproduce the bug.

Expected behavior

What would you expect to happen when following the steps above?

To return empty captions

Please tell us about your environment

We want to make sure the problem isn't specific to your operating system or programming language.

  • Operating System/Version: Ubuntu 22.04
  • Language: Python 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions