Skip to content

Conversation

@dariopellegrino00
Copy link
Collaborator

No description provided.

fix error events not notified by module #17
@dariopellegrino00 dariopellegrino00 self-assigned this Oct 8, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements OpenAI speech detection functionality to track when OpenAI starts and stops speaking during audio streaming sessions. The implementation adds event-driven notifications for speech state changes to enable better handling of conversation flow and interruptions.

  • Adds speech state tracking with m_openai_speaking and m_response_audio_done flags
  • Implements speech start/stop detection logic in the audio playback pipeline
  • Introduces new event types for notifying external systems of speech state changes

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
openai_audio_streamer_glue.cpp Core speech detection logic, state tracking, and event notification methods
mod_openai_audio_stream.h Event constant definitions for speech start/stop notifications
mod_openai_audio_stream.c Event registration and cleanup for new speech detection events

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


if (as->clear_requested()) {
switch_buffer_zero(tech_pvt->playback_buffer);
inuse = 0;
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

Setting inuse = 0 after clearing the buffer could cause incorrect behavior. The inuse variable represents the actual bytes in the buffer, and after switch_buffer_zero() it should reflect the buffer's empty state, but this assignment might interfere with the subsequent logic that depends on the actual buffer size.

Suggested change
inuse = 0;
inuse = switch_buffer_inuse(tech_pvt->playback_buffer);

Copilot uses AI. Check for mistakes.
switch_buffer_write(tech_pvt->playback_buffer, chunk.data(), chunk.size() * sizeof(int16_t));
} else if (inuse == 0) {
// Openai just finished speaking for interruption or end of response
if(as->is_openai_speaking() && as->is_response_audio_done()) {
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

[nitpick] The condition combines two state checks that could be confusing. Consider adding a comment explaining when both conditions are true simultaneously, or create a helper method like should_stop_speech() to encapsulate this logic.

Copilot uses AI. Check for mistakes.
Signed-off-by: Dario Pellegrino <dario.pellegrino@voismart.it>
@dariopellegrino00 dariopellegrino00 merged commit 60fbeec into develop Oct 8, 2025
2 checks passed
@dariopellegrino00 dariopellegrino00 deleted the openai-speech-detect branch October 8, 2025 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants