twilio / twilio/twilio-python

[BUG] barge_in Argument in <Gather> Verb Not Functioning

Open
#860 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
Python
Stars
2.1k
Forks
815
Avg merge
2d 13h
Merged PRs (30d)
2

Description

Describe the bug

Hello,

I'm trying to use the Gather verb in Twilio to allow users to interrupt a Say message by speaking. However, setting barge_in=True appears to have no effect — the Say message continues to play and is not interrupted by speech input.

Could you please help me resolve this issue?

Code snippet
# -*- coding: iso-8859-1 -*-
from fastapi import FastAPI, WebSocket,Response
from fastapi.responses import HTMLResponse
from twilio.twiml.voice_response import VoiceResponse, Start, Gather
import uvicorn

app = FastAPI()

@app.post("/incoming")
async def start():
    response = VoiceResponse()
    gather = Gather(
        input='speech',
        barge_in=True,  
        timeout=5
    )
    gather.say("Hallo, ich bin ein Assistent. Bitte gebe 1, 2 oder 3 ein. Hast du sonst noch wünsche?",language= "de-DE", voice= "Polly.Vicki-Neural")
    response.append(gather)
    print(response)
    return HTMLResponse(content=str(response), media_type="application/xml")

if __name__ == "__main__":
    uvicorn.run("Funktionierende_Lösung:app", host="0.0.0.0", port=5050, reload=True)
Actual behavior

The Say message continues to play and is not interrupted by speech input.

Expected behavior

The Say message should be interrupted by speech input and should stop to play.

twilio-python version

9.4.5

Python version

3.12

Logs or error messages

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied FastAPI example with twilio-python 9.4.5, then inspect the Gather entry point in twilio.twiml.voice_response and the generated TwiML. Compare the serialized barge_in attribute with Twilio's expected Gather behavior. Done means identifying whether the library or Twilio handling prevents interruption and adding a verified fix or documenting the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.