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

LiveTranscription #127

Closed
SishaarRao opened this issue Aug 4, 2023 · 5 comments
Closed

LiveTranscription #127

SishaarRao opened this issue Aug 4, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@SishaarRao
Copy link

What is the current behavior?

I keep seeing the following error emitted by my server

Task exception was never retrieved
future: <Task finished name='Task-192191' coro=<LiveTranscription._start() done, defined at /Users/sishaar/.pyenv/versions/3.11.4/lib/python3.11/site-packages/deepgram/transcription.py:178> exception=ConnectionClosedOK(Close(code=1000, reason=''), Close(code=1000, reason=''), True)>
Traceback (most recent call last):
  File "/Users/sishaar/.pyenv/versions/3.11.4/lib/python3.11/site-packages/deepgram/transcription.py", line 222, in _start
    await self._socket.send(body)
  File "/Users/sishaar/.pyenv/versions/3.11.4/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 635, in send
    await self.ensure_open()
  File "/Users/sishaar/.pyenv/versions/3.11.4/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 935, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)

Here is the file I use to manage my Deepgram connections - am I not registering/handling errors correctly?

class _DeepgramConnectionPool:
  def __init__(self):
    self.connections: LiveTranscription = []
    self.deepgram_hosted = Deepgram('<elided>')
    self.deepgram_onprem = Deepgram({'api_key': '', 'api_url': '<elided>'})

  async def get_connection(self, config: dict = {}):
    # default to use hosted deepgram
    self.deepgram = self.deepgram_hosted
    if config.get("enable_to_use_deepgram_on_premise") == "true":
      self.deepgram = self.deepgram_onprem
    try:
      deepgram_config = config.get('country_code_configs', {})
      model = deepgram_config.get("model", '<elided>')
      tier = 'enhanced' if model == 'nooks' else deepgram_config.get("tier", 'base')
      version = 'v1' if model == 'nooks' else deepgram_config.get('version', 'latest')

      async def _get_connection():
        return await self.deepgram.transcription.live(
          encoding='mulaw',
          model=model,
          tier=tier,
          version=version,
          sample_rate=8000,
          punctuate=True,
          interim_results=True,
          language='en-US',
          times=False,
        )

      connection: LiveTranscription = await Retry(_get_connection, delay_s=0.1, factor=1.2)
      connection.register_handler(LiveTranscriptionEvent.ERROR, lambda error: logger.error('Error during connection', exception=error))
      return connection
    except ConnectionClosedOK:
      logger.log('Deepgram websocket connection closed')
    except Exception as e:
      logger.error('Error creating connection: ', exception=e)
      raise e

DeepgramConnectionPool = _DeepgramConnectionPool()

Later on, I close the connection with the following piece of code

    async def close_deepgram(self):
        self.logger.debug("Closing Deepgram Connection")
        if self.deepgram:
            await self.deepgram.finish()
            self.logger.log('Closed Deepgram Connection')

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: MacOS
  • **Language: Python
@DamienDeepgram
Copy link
Contributor

Are you using the keepalive message when your not sending any audio we will close the stream unless you send us a keepalive message

https://developers.deepgram.com/reference/streaming#stream-keepalive

@dvonthenen dvonthenen self-assigned this Nov 16, 2023
@dvonthenen
Copy link
Contributor

The live client is getting reworked. Please check back when PR is merged.

@jpvajda jpvajda added this to the Python SDK v3 Release milestone Nov 17, 2023
@jpvajda jpvajda added the bug Something isn't working label Nov 17, 2023
@dvonthenen
Copy link
Contributor

A new release was just posted which should address this problem, please take a look:
https://github.com/deepgram/deepgram-python-sdk/releases/tag/v3.0.0-alpha.1

@dvonthenen
Copy link
Contributor

Hi @SishaarRao have you been able to try the latest v3 release?

@dvonthenen
Copy link
Contributor

Closing due to inactivity. If there is still a problem with the latest release, please reopen or file a new issue. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants