Skip to content
Merged
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
25 changes: 15 additions & 10 deletions deepgram/transcription.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PrerecordedTranscription:
_root = "/listen"

def __init__(self, options: Options,
transcription_options: PrerecordedOptions) -> None:
transcription_options: PrerecordedOptions, endpoint) -> None:
"""
This function initializes the options and transcription_options for the PrerecordedTranscription class.

Expand All @@ -27,8 +27,9 @@ def __init__(self, options: Options,
:return: Nothing.

"""

self.options = options
if endpoint is not None:
self._root = endpoint
self.transcription_options = transcription_options

async def __call__(
Expand Down Expand Up @@ -69,7 +70,7 @@ class SyncPrerecordedTranscription:
_root = "/listen"

def __init__(self, options: Options,
transcription_options: PrerecordedOptions) -> None:
transcription_options: PrerecordedOptions, endpoint) -> None:
"""
This function initializes the options and transcription_options for the PrerecordedTranscription class.

Expand All @@ -80,6 +81,8 @@ def __init__(self, options: Options,
"""

self.options = options
if endpoint is not None:
self._root = endpoint
self.transcription_options = transcription_options

def __call__(
Expand Down Expand Up @@ -126,7 +129,7 @@ class LiveTranscription:
MESSAGE_TIMEOUT = 1.0

def __init__(self, options: Options,
transcription_options: LiveOptions) -> None:
transcription_options: LiveOptions, endpoint) -> None:
"""
The __init__ function is called when an instance of the class is created.
It initializes all of the attributes that are part of the object, and can be
Expand All @@ -140,6 +143,8 @@ def __init__(self, options: Options,
"""

self.options = options
if endpoint is not None:
self._root = endpoint
self.transcription_options = transcription_options
self.handlers: List[Tuple[LiveTranscriptionEvent, EventHandler]] = []
# all received messages
Expand Down Expand Up @@ -331,39 +336,39 @@ def __init__(self, options: Options) -> None:

async def prerecorded(
self, source: TranscriptionSource,
options: PrerecordedOptions = None, **kwargs
options: PrerecordedOptions = None, endpoint = "/listen", **kwargs
) -> PrerecordedTranscriptionResponse:
"""Retrieves a transcription for an already-existing audio file,
local or web-hosted."""
if options is None:
options = {}
full_options = cast(PrerecordedOptions, {**options, **kwargs})
return await PrerecordedTranscription(
self.options, full_options
self.options, full_options, endpoint
)(source)


def sync_prerecorded(
self, source: TranscriptionSource,
options: PrerecordedOptions = None, **kwargs
options: PrerecordedOptions = None, endpoint = "/listen", **kwargs
) -> PrerecordedTranscriptionResponse:
"""Retrieves a transcription for an already-existing audio file,
local or web-hosted."""
if options is None:
options = {}
full_options = cast(PrerecordedOptions, {**options, **kwargs})
return SyncPrerecordedTranscription(
self.options, full_options
self.options, full_options, endpoint
)(source)


async def live(
self, options: LiveOptions = None, **kwargs
self, options: LiveOptions = None, endpoint = "/listen", **kwargs
) -> LiveTranscription:
"""Provides a client to send raw audio data to be transcribed."""
if options is None:
options = {}
full_options = cast(LiveOptions, {**options, **kwargs})
return await LiveTranscription(
self.options, full_options
self.options, full_options, endpoint
)()