deepgram-python-sdk icon indicating copy to clipboard operation
deepgram-python-sdk copied to clipboard

Fix Mismatch Structs on STT REST

Open davidvonthenen opened this issue 1 year ago • 1 comments

Proposed changes

Addresses: https://github.com/deepgram/deepgram-python-sdk/issues/466

Verified working modifying an example: examples/speech-to-text/rest/url

Options:

        options: PrerecordedOptions = PrerecordedOptions(
            model="nova-2",
            smart_format=True,
            paragraphs=True,
        )

Result:

response: {
    "metadata": {
        "transaction_key": "deprecated",
        "request_id": "3c6973b5-d755-4687-97db-938530c82bd6",
        "sha256": "5324da68ede209a16ac69a38e8cd29cee4d754434a041166cda3a1f5e0b24566",
        "created": "2024-09-26T01:37:48.494Z",
        "duration": 17.566313,
        "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": "Yep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while, you could miss it.",
                        "confidence": 0.99853814,
                        "words": [
                            {
                                "word": "yep",
                                "start": 5.52,
                                "end": 6.02,
                                "confidence": 0.995842,
                                "punctuated_word": "Yep."
                            },
                            {
                                "word": "i",
                                "start": 7.04,
                                "end": 7.2799997,
                                "confidence": 0.51270777,
                                "punctuated_word": "I"
                            },
                            {
                                "word": "said",
                                "start": 7.2799997,
                                "end": 7.44,
                                "confidence": 0.96725076,
                                "punctuated_word": "said"
                            },
                            {
                                "word": "it",
                                "start": 7.44,
                                "end": 7.6,
                                "confidence": 0.9997285,
                                "punctuated_word": "it"
                            },
                            {
                                "word": "before",
                                "start": 7.6,
                                "end": 7.9199996,
                                "confidence": 0.7845937,
                                "punctuated_word": "before,"
                            },
                            {
                                "word": "and",
                                "start": 7.9199996,
                                "end": 8.16,
                                "confidence": 0.9998627,
                                "punctuated_word": "and"
                            },
                            {
                                "word": "i'll",
                                "start": 8.16,
                                "end": 8.32,
                                "confidence": 0.9998943,
                                "punctuated_word": "I'll"
                            },
                            {
                                "word": "say",
                                "start": 8.32,
                                "end": 8.48,
                                "confidence": 0.9996518,
                                "punctuated_word": "say"
                            },
                            {
                                "word": "it",
                                "start": 8.48,
                                "end": 8.639999,
                                "confidence": 0.99982834,
                                "punctuated_word": "it"
                            },
                            {
                                "word": "again",
                                "start": 8.639999,
                                "end": 9.139999,
                                "confidence": 0.97370684,
                                "punctuated_word": "again."
                            },
                            {
                                "word": "life",
                                "start": 9.991312,
                                "end": 10.391313,
                                "confidence": 0.99573696,
                                "punctuated_word": "Life"
                            },
                            {
                                "word": "moves",
                                "start": 10.391313,
                                "end": 10.711312,
                                "confidence": 0.9988587,
                                "punctuated_word": "moves"
                            },
                            {
                                "word": "pretty",
                                "start": 10.711312,
                                "end": 11.031313,
                                "confidence": 0.9996013,
                                "punctuated_word": "pretty"
                            },
                            {
                                "word": "fast",
                                "start": 11.031313,
                                "end": 11.531313,
                                "confidence": 0.9995537,
                                "punctuated_word": "fast."
                            },
                            {
                                "word": "you",
                                "start": 12.071312,
                                "end": 12.231313,
                                "confidence": 0.9514584,
                                "punctuated_word": "You"
                            },
                            {
                                "word": "don't",
                                "start": 12.231313,
                                "end": 12.4713125,
                                "confidence": 0.99988735,
                                "punctuated_word": "don't"
                            },
                            {
                                "word": "stop",
                                "start": 12.4713125,
                                "end": 12.711312,
                                "confidence": 0.99979633,
                                "punctuated_word": "stop"
                            },
                            {
                                "word": "and",
                                "start": 12.711312,
                                "end": 12.871312,
                                "confidence": 0.9987136,
                                "punctuated_word": "and"
                            },
                            {
                                "word": "look",
                                "start": 12.871312,
                                "end": 13.031313,
                                "confidence": 0.9996673,
                                "punctuated_word": "look"
                            },
                            {
                                "word": "around",
                                "start": 13.031313,
                                "end": 13.351313,
                                "confidence": 0.9995766,
                                "punctuated_word": "around"
                            },
                            {
                                "word": "once",
                                "start": 13.351313,
                                "end": 13.591312,
                                "confidence": 0.9981976,
                                "punctuated_word": "once"
                            },
                            {
                                "word": "in",
                                "start": 13.591312,
                                "end": 13.751312,
                                "confidence": 0.99853814,
                                "punctuated_word": "in"
                            },
                            {
                                "word": "a",
                                "start": 13.751312,
                                "end": 13.831312,
                                "confidence": 0.9861081,
                                "punctuated_word": "a"
                            },
                            {
                                "word": "while",
                                "start": 13.831312,
                                "end": 14.331312,
                                "confidence": 0.92629486,
                                "punctuated_word": "while,"
                            },
                            {
                                "word": "you",
                                "start": 14.631312,
                                "end": 14.791312,
                                "confidence": 0.99702364,
                                "punctuated_word": "you"
                            },
                            {
                                "word": "could",
                                "start": 14.791312,
                                "end": 14.951313,
                                "confidence": 0.9983536,
                                "punctuated_word": "could"
                            },
                            {
                                "word": "miss",
                                "start": 14.951313,
                                "end": 15.191313,
                                "confidence": 0.9984425,
                                "punctuated_word": "miss"
                            },
                            {
                                "word": "it",
                                "start": 15.191313,
                                "end": 15.691313,
                                "confidence": 0.9950415,
                                "punctuated_word": "it."
                            }
                        ],
                        "paragraphs": {
                            "transcript": "\nYep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while, you could miss it.",
                            "paragraphs": [
                                {
                                    "sentences": [
                                        {
                                            "text": "Yep.",
                                            "start": 5.52,
                                            "end": 6.02
                                        },
                                        {
                                            "text": "I said it before, and I'll say it again.",
                                            "start": 7.04,
                                            "end": 9.139999
                                        },
                                        {
                                            "text": "Life moves pretty fast.",
                                            "start": 9.991312,
                                            "end": 11.531313
                                        },
                                        {
                                            "text": "You don't stop and look around once in a while, you could miss it.",
                                            "start": 12.071312,
                                            "end": 15.691313
                                        }
                                    ],
                                    "start": 5.52,
                                    "end": 15.691313,
                                    "num_words": 28
                                }
                            ]
                        }
                    }
                ]
            }
        ]
    }
}

Types of changes

What types of changes does your code introduce to the community Python SDK? Put an x in the boxes that apply

  • [x] Bugfix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] Documentation update or tests (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • [x] I have read the CONTRIBUTING doc
  • [x] I have lint'ed all of my code using repo standards
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] I have added necessary documentation (if appropriate)

Further comments

NA

Summary by CodeRabbit

  • New Features

    • Introduced new entities for handling WebSocket and REST responses, including ListenWSWord, ListenWSAlternative, ListenWSChannel, and their REST counterparts.
    • Enhanced data representation for WebSocket responses, improving the handling of words, alternatives, and channels.
  • Bug Fixes

    • Clarified the handling of _asyncio_thread in the Microphone class for better state management.
  • Refactor

    • Streamlined import statements across various modules to focus on new listening functionalities, removing outdated entities.

davidvonthenen avatar Sep 26 '24 02:09 davidvonthenen

Walkthrough

The changes involve a comprehensive restructuring of import statements and class definitions across multiple files in the Deepgram client library. The modifications primarily focus on removing outdated entities such as Alternative, Channel, and Word, and replacing them with new entities related to WebSocket and REST functionalities, including ListenWSAlternative, ListenWSChannel, ListenWSWord, ListenRESTAlternative, ListenRESTChannel, and ListenRESTWord. This shift indicates a reorganization of the module's structure to enhance clarity and functionality.

Changes

File Path Change Summary
deepgram/__init__.py Removed imports for Alternative, Channel, and Word; added imports for ListenWSAlternative, ListenWSChannel, ListenWSWord, ListenRESTAlternative, ListenRESTChannel, and ListenRESTWord.
deepgram/audio/microphone/microphone.py Updated _asyncio_thread attribute to be Optional[threading.Thread] = None and simplified its handling in start and finish methods.
deepgram/client.py Removed imports for Alternative, Channel, and Word; added imports for ListenWSAlternative, ListenWSChannel, ListenWSWord, ListenRESTAlternative, ListenRESTChannel, and ListenRESTWord.
deepgram/clients/__init__.py Removed imports for Alternative, Channel, and Word; added imports for ListenWSAlternative, ListenWSChannel, ListenWSWord, ListenRESTAlternative, ListenRESTChannel, and ListenRESTWord.
deepgram/clients/common/__init__.py Removed exports for Word, Alternative, and Channel.
deepgram/clients/common/v1/__init__.py Removed imports for Word, Alternative, and Channel.
deepgram/clients/common/v1/shared_response.py Removed classes Word, Alternative, and Channel.
deepgram/clients/listen/__init__.py Removed exports for Alternative, Channel, and Word; added exports for ListenWSAlternative, ListenWSChannel, ListenWSWord, ListenRESTAlternative, ListenRESTChannel, and ListenRESTWord.
deepgram/clients/listen/client.py Removed variables for Alternative, Channel, and Word; added variables for ListenWSAlternative, ListenWSChannel, ListenWSWord, ListenRESTAlternative, ListenRESTChannel, and ListenRESTWord.
deepgram/clients/listen/v1/__init__.py Removed imports for Alternative, Channel, and Word; added imports for ListenWSAlternative, ListenWSChannel, ListenWSWord, ListenRESTAlternative, ListenRESTChannel, and ListenRESTWord.
deepgram/clients/listen/v1/rest/__init__.py Removed exports for Alternative, Channel, and Word; added exports for ListenRESTAlternative, ListenRESTChannel, and ListenRESTWord.
deepgram/clients/listen/v1/rest/response.py Introduced new classes ListenRESTWord, ListenRESTAlternative, and ListenRESTChannel, replacing previous classes and updating attributes accordingly.
deepgram/clients/listen/v1/websocket/__init__.py Removed exports for Alternative, Channel, and Word; added exports for ListenWSAlternative, ListenWSChannel, and ListenWSWord.
deepgram/clients/listen/v1/websocket/response.py Introduced new classes ListenWSWord, ListenWSAlternative, and ListenWSChannel, updating the response structure to align with new naming conventions.

Possibly related PRs

  • #434: Modifies the deepgram/__init__.py file by changing import statements related to WebSocket functionalities, aligning with the main PR's focus on updating import statements for WebSocket-related entities.
  • #462: Involves changes to the deepgram/__init__.py file, specifically enhancing error handling capabilities, which may relate to the overall restructuring of imports and functionalities in the main PR.

Suggested reviewers

  • jpvajda
  • SandraRodgers
  • lukeocodes

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

:heart: Share
:placard: Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Sep 26 '24 02:09 coderabbitai[bot]