Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Implementation for SITS Features #255

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion deepgram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging, verboselogs

# listen client
from .client import ListenClient
from .client import Listen, Read

# live
from .client import LiveTranscriptionEvents
Expand All @@ -33,10 +33,29 @@
BufferSource,
ReadStreamSource,
PrerecordedOptions,
Sentiment,
)
from .client import (
AsyncPrerecordedResponse,
PrerecordedResponse,
SyncPrerecordedResponse,
)

# read
from .client import AnalyzeClient, AsyncAnalyzeClient
from .client import (
AnalyzeSource,
TextSource,
UrlSource,
BufferSource,
AnalyzeStreamSource,
AnalyzeOptions,
Sentiment,
)
from .client import (
AsyncAnalyzeResponse,
AnalyzeResponse,
SyncAnalyzeResponse,
)

# manage
Expand Down
29 changes: 27 additions & 2 deletions deepgram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os

# listen client
from .clients import ListenClient
from .clients import Listen, Read

# live
from .clients import LiveClient, AsyncLiveClient
Expand All @@ -34,12 +34,33 @@
BufferSource,
ReadStreamSource,
PrerecordedOptions,
Sentiment,
)

# prerecorded client responses
from .clients import (
AsyncPrerecordedResponse,
PrerecordedResponse,
SyncPrerecordedResponse,
)

# analyze
from .clients import AnalyzeClient, AsyncAnalyzeClient
from .clients import (
AnalyzeSource,
TextSource,
UrlSource,
BufferSource,
AnalyzeStreamSource,
AnalyzeOptions,
Sentiment,
)

# read client responses
from .clients import (
AsyncAnalyzeResponse,
AnalyzeResponse,
SyncAnalyzeResponse,
)

# manage client classes/input
Expand Down Expand Up @@ -153,7 +174,11 @@ def __init__(

@property
def listen(self):
return ListenClient(self.config)
return Listen(self.config)

@property
def read(self):
return Read(self.config)

@property
def manage(self):
Expand Down
22 changes: 21 additions & 1 deletion deepgram/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# SPDX-License-Identifier: MIT

# listen
from .listen import ListenClient
from .listen import Listen
from .read import Read

# live
from .live import LiveClient, AsyncLiveClient
Expand All @@ -19,6 +20,7 @@
# prerecorded
from .prerecorded import PreRecordedClient, AsyncPreRecordedClient
from .prerecorded import PrerecordedOptions
from .prerecorded import Sentiment
from .prerecorded import (
PrerecordedSource,
FileSource,
Expand All @@ -29,6 +31,24 @@
from .prerecorded import (
AsyncPrerecordedResponse,
PrerecordedResponse,
SyncPrerecordedResponse,
)

# analyze
from .analyze import AnalyzeClient, AsyncAnalyzeClient
from .analyze import AnalyzeOptions
from .analyze import Sentiment
from .analyze import (
AnalyzeSource,
TextSource,
UrlSource,
BufferSource,
AnalyzeStreamSource,
)
from .analyze import (
AsyncAnalyzeResponse,
AnalyzeResponse,
SyncAnalyzeResponse,
)

# manage
Expand Down
18 changes: 18 additions & 0 deletions deepgram/clients/analyze/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from .client import AnalyzeClient
from .client import AsyncAnalyzeClient
from .client import AnalyzeOptions
from .client import Sentiment
from .source import (
AnalyzeSource,
TextSource,
UrlSource,
BufferSource,
AnalyzeStreamSource,
)
from .client import AsyncAnalyzeResponse, AnalyzeResponse, SyncAnalyzeResponse

from ...options import DeepgramClientOptions
72 changes: 72 additions & 0 deletions deepgram/clients/analyze/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2024 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from .v1.client import AnalyzeClient as AnalyzeClientLatest
from .v1.async_client import AsyncAnalyzeClient as AsyncAnalyzeClientLatest
from .v1.options import AnalyzeOptions as AnalyzeOptionsLatest
from .source import AnalyzeSource, TextSource, UrlSource
from .v1.response import (
SyncAnalyzeResponse as SyncAnalyzeResponseLatest,
AnalyzeResponse as AnalyzeResponseLatest,
AsyncAnalyzeResponse as AsyncAnalyzeResponseLatest,
)
from .enums import Sentiment

"""
The client.py points to the current supported version in the SDK.
Older versions are supported in the SDK for backwards compatibility.
"""


# input
class AnalyzeOptions(AnalyzeOptionsLatest):
"""
Please see AnalyzeOptionsLatest for details
"""

pass


class AsyncAnalyzeResponse(AsyncAnalyzeResponseLatest):
"""
Please see AnalyzeResponseLatest for details
"""

pass


class AnalyzeResponse(AnalyzeResponseLatest):
"""
Please see AnalyzeResponseLatest for details
"""

pass


class SyncAnalyzeResponse(SyncAnalyzeResponseLatest):
"""
Please see AnalyzeResponseLatest for details
"""

pass


# clients
class AnalyzeClient(AnalyzeClientLatest):
"""
Please see AnalyzeClientLatest for details
"""

def __init__(self, config):
self.config = config
super().__init__(config)


class AsyncAnalyzeClient(AsyncAnalyzeClientLatest):
"""
Please see AsyncAnalyzeClientLatest for details
"""

def __init__(self, config):
super().__init__(config)
16 changes: 16 additions & 0 deletions deepgram/clients/analyze/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from enum import Enum

"""
Constants mapping to events from the Deepgram API
"""


class Sentiment(Enum):
UNKNOWN = ""
NEGATIVE = "negative"
NEUTRAL = "neutral"
POSITIVE = "positive"
37 changes: 37 additions & 0 deletions deepgram/clients/analyze/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT


class DeepgramError(Exception):
"""
Exception raised for unknown errors related to the Deepgram API.

Attributes:
message (str): The error message describing the exception.
"""

def __init__(self, message: str):
super().__init__(message)
self.name = "DeepgramError"
self.message = message

def __str__(self):
return f"{self.name}: {self.message}"


class DeepgramTypeError(Exception):
"""
Exception raised for unknown errors related to unknown Types for Transcription.

Attributes:
message (str): The error message describing the exception.
"""

def __init__(self, message: str):
super().__init__(message)
self.name = "DeepgramTypeError"
self.message = message

def __str__(self):
return f"{self.name}: {self.message}"
17 changes: 17 additions & 0 deletions deepgram/clients/analyze/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from .source import AnalyzeSource


def is_buffer_source(provided_source: AnalyzeSource) -> bool:
return "buffer" in provided_source


def is_readstream_source(provided_source: AnalyzeSource) -> bool:
return "stream" in provided_source


def is_url_source(provided_source: AnalyzeSource) -> bool:
return "url" in provided_source
53 changes: 53 additions & 0 deletions deepgram/clients/analyze/source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from typing import Union
from io import BufferedReader
from typing_extensions import TypedDict


class AnalyzeStreamSource(TypedDict):
"""
Represents a data source for reading binary data from a stream-like source.

This class is used to specify a source of binary data that can be read from
a stream, such as an audio file in .wav format.

Attributes:
stream (BufferedReader): A BufferedReader object for reading binary data.
"""

stream: BufferedReader


class UrlSource(TypedDict):
"""
Represents a data source for specifying the location of a file via a URL.

This class is used to specify a hosted file URL, typically pointing to an
externally hosted file, such as an audio file hosted on a server or the internet.

Attributes:
url (str): The URL pointing to the hosted file.
"""

url: str


class BufferSource(TypedDict):
"""
Represents a data source for handling raw binary data.

This class is used to specify raw binary data, such as audio data in its
binary form, which can be captured from a microphone or generated synthetically.

Attributes:
buffer (bytes): The binary data.
"""

buffer: bytes


AnalyzeSource = Union[UrlSource, BufferSource, AnalyzeStreamSource]
TextSource = Union[BufferSource, AnalyzeStreamSource]
10 changes: 10 additions & 0 deletions deepgram/clients/analyze/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2024 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from .client import AnalyzeClient
from .async_client import AsyncAnalyzeClient
from .options import AnalyzeOptions
from ....options import DeepgramClientOptions
from .response import AsyncAnalyzeResponse, AnalyzeResponse
from ..enums import Sentiment
Loading