from flask import Flask, request, Responseimport requestsfrom twilio.twiml.voice_response import VoiceResponse, Play, Start, Streamfrom twilio.rest import Clientimport timeimport osfrom google.cloud import speech_v1 as speechfrom google.cloud.speech_v1 import typesimport threadingimport queueimport base64app = Flask(__name__)#Google Cloud Credentials environment variableos.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './google_credentials.json'# Twilio credentialsaccount_sid = ['TWILIO_SID']auth_token = ['TWILIO_AUTH']twilio_client = Client(account_sid, auth_token)speech_client = speech.SpeechClient()# Create a queue to store audio chunksaudio_chunks_queue = queue.Queue()# A simple in-memory structure to store call associations# In production, you might want to use a databasecall_associations = {}response = None@app.route("/incoming_call", methods=['POST'])def handle_incoming_call():"""Responds to incoming calls and sets up segmented recording of inbound audio.""" response = VoiceResponse() start = Start() stream = Stream(url='wss://b32e-2603-8081-4c00-3a7c-2d64-d183-b6e6-f523.ngrok-free.app/stream_audio') start.append(stream) response.append(start) twiml_response_str = str(response) print("Generated TwiML Response:\n", twiml_response_str) print("incoming call") return Response(str(response), mimetype='text/xml')@app.route("/stream_audio", methods=['POST'])def stream_audio():"""Receive streamed audio from Twilio and add it to the queue.""" print("Audio is streaming") audio_data = request.get_data() audio_chunks_queue.put(audio_data) return ('', 204)
The desired result is to get the print statement 'Audio is streaming', but I get this instead from Twilio Dashboard
Message
Invalid URL.
Error Description
Error - 11100 ### Invalid URL format The format of the provided URL is invalid.
Possible SolutionsMake sure you submit a fully qualified URL including:
protocol (http:// or https://)hostnamefile pathproperly url-encoded query parametersTwilio must be able to reach this URL over the public Internet.
Possible CausesBad URL for phone number configurationBad URL passed to outgoing call REST requestBad URL in Play or Redirect Verb BodyBad URL provided for a verb's action attributeNo URL provided in Record verb action attribute when modifying a live callUnsupported characters in auth portion of URL
Should I be using https instead? Using https gives me the same error. Or do I need to import a library to use wss?