Retrieve media URL with endpoints

I’ve seen and tried out playing an mp3 file that was stored in a table as a media file, as discussed in this thread: Get url of file saved in the anvil table

However, I want to access the URL via an endpoint, like

@anvil.server.http_endpoint('/audio/:input')
def call_tts(input):
  
  r = anvil.server.HttpResponse()
  r.headers['Access-Control-Allow-Origin'] = '*'
  r.headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
  r.headers['Access-Control-Request-Method'] = '*'
  r.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
  r.status = 200
  
  audio_url = app_tables.media.get(name='tts')['audio'].url
  r.body = audio_url

  return r

When I access the URL on the webpage and try to play it via JavaScript, I get a 400 (Bad Request) error. Any other way to do this? I am just accessing Anvil via endpoints for this app.

Well, there doesn’t seem to be a way to get there from here. I can get the URL of an audio file after storing it in a table and then passing it to a function only when the code is on Anvil as Client side - meaning that the code displays stuff via an iFrame. Although this works, it means that I would need a separate Anvil app for each page that needs the same thing, since the iFrame can’t pass any variables about the current webpage that it is in. Wish there was a way to set a temp URL for media objects in tables (or elsewhere) that could be accessed from anywhere.

The whole aim here is to play an audio file produced through Google’s Colab environment (text-to-speech via the cloud). Has anyone figured out an elegant way to store a media file produced in Colab so that it can be accessed via a URL?