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

Second initialization of LiveTranscription doesn't send data to deepgram #140

Closed
tipu opened this issue Sep 19, 2023 · 5 comments
Closed
Assignees

Comments

@tipu
Copy link

tipu commented Sep 19, 2023

What is the current behavior?

I have an interaction with a stream of audio that should be transcripted. It's not like a podcast where it is a single large stream, rather it's more conversational where there could be a sentence and a pause of 30 seconds or more and then another sentence. I figure the best thing to do is use a unique instance for each interaction.

The problem is that subsequent instances of the LiveTranscription object don't seem to send data. The first time through the code it works fine but when deepgramLive is initialized a second time, the TRANSCRIPT_RECEIVED handler is never fired until eventually it closes, that is, the CLOSE handler is called.

One thing to note is if I don't reinitialize deepgramLive, the stream can pick up subsequent phrases.

Steps to reproduce

@app.websocket("/ws/test")
async def test(websocket: WebSocket):
    await websocket.accept()
    async def receive_deepgram_transcript(msg):
        nonlocal transcript
        if msg.get("is_final"):
            transcript = (
                msg.get("channel", {})
                .get("alternatives", [{}])[0]
                .get("transcript", "")
            )
            if transcript != "":
                print(transcript)

    deepgramLive = None
    transcript = None
    while True:
        while not transcript:
            if not deepgramLive:
                deepgramLive = await dg_client.transcription.live({ 'punctuate': True, 'interim_results': False, 'language': 'en-US' })
                deepgramLive.registerHandler(deepgramLive.event.CLOSE, lambda c: print(f'Connection closed with code {c}.'))
                deepgramLive.registerHandler(deepgramLive.event.TRANSCRIPT_RECEIVED, receive_deepgram_transcript)
            data = await websocket.receive()
            deepgramLive.send(data['bytes'])
        else:
            print("closing")
            await deepgramLive.finish()
            deepgramLive = None
@tipu
Copy link
Author

tipu commented Sep 29, 2023

I ended up resolving this using a raw websocket and spamming the KeepAlive message every 5 seconds.

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

The live client is getting reworked to include the KeepAlive message. Please check back when the PR is merged.

@davidvonthenen
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

@davidvonthenen
Copy link
Contributor

The alpha.5 release is out. Have you been able to try this out?

@davidvonthenen
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
Projects
None yet
Development

No branches or pull requests

3 participants