Skip to content

Update streaming_transcription.py to allow longer audio input per stream#13891

Open
deliaqi wants to merge 5 commits intoGoogleCloudPlatform:mainfrom
deliaqi:patch-2
Open

Update streaming_transcription.py to allow longer audio input per stream#13891
deliaqi wants to merge 5 commits intoGoogleCloudPlatform:mainfrom
deliaqi:patch-2

Conversation

@deliaqi
Copy link
Contributor

@deliaqi deliaqi commented Mar 6, 2026

Description

Update sample code for Agent Assist Voice Transcription.

@deliaqi deliaqi requested review from a team as code owners March 6, 2026 01:09
@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: dialogflow Issues related to the Dialogflow API. labels Mar 6, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the streaming_transcription.py sample for Agent Assist Voice Transcription by enabling the processing of much longer continuous audio inputs. It achieves this by modifying the stream's half-closing mechanism to allow for extended transcription periods and by adding specific error handling for OutOfRange exceptions, ensuring that long-running streams can recover and continue. These changes make the sample more robust and practical for real-world applications requiring prolonged audio transcription.

Highlights

  • Extended Audio Input: The sample code now supports longer audio inputs per stream by delaying the half-closing of the stream until a specified duration (90 seconds) has passed, preventing premature termination for extended transcription sessions.
  • Robust Error Handling: Implemented handling for the OutOfRange exception, which now gracefully restarts the transcription stream when the maximum audio duration is exceeded, improving the sample's resilience.
  • New Configuration Constant: Introduced HALF_CLOSE_DURATION_MS to explicitly define the duration after which a stream can be half-closed, making the behavior configurable and clearer.
Changelog
  • dialogflow/streaming_transcription.py
    • Updated the copyright year from 2023 to 2026.
    • Imported the OutOfRange exception from google.api_core.exceptions.
    • Added a new constant HALF_CLOSE_DURATION_MS set to 90 seconds.
    • Modified the stream half-closing logic to be conditional on stream.is_final_offset exceeding HALF_CLOSE_DURATION_MS.
    • Introduced an except OutOfRange block to catch maximum audio duration errors and restart the stream.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the streaming transcription sample to support longer audio streams. This is achieved by delaying the half-closing of the gRPC stream and by handling the OutOfRange exception to restart the stream when the audio duration limit is reached. The overall approach is sound, but I have a suggestion to simplify the logic for restarting the stream, which could improve maintainability.

@deliaqi
Copy link
Contributor Author

deliaqi commented Mar 6, 2026

The failing checks are not relevant to this change, I can create a separate pull request to fix those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: dialogflow Issues related to the Dialogflow API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant