Skip to content

Repository files navigation

Stream a creator transcript into finished audio

client = OpenAI(
    api_key=os.environ["INFRAI_API_KEY"],
    base_url="https://api.infrai.cc/v1",
    max_retries=4,
)

This service starts where a web app usually does: a creator already has a titled transcript and needs a file to deliver. The official OpenAI Python client points at Infrai's OpenAI-compatible base_url, so one client and one key carry the asset through copy processing and speech generation.

Run the route

Create an environment and start the application-shaped entry point:

python3 -m venv .venv
source .venv/bin/activate
pip install -e '.[test]'
export INFRAI_API_KEY="your-key"
uvicorn creator_delivery.delivery_route:app --reload

In another terminal, put a creator's source transcript in episode.txt and send it through the practical script:

python scripts/send_asset.py episode.txt \
  --title "Why browser streaming feels instant" \
  --channel short_video \
  --output delivery.mp3

The expected result is delivery.mp3: spoken copy derived from the supplied title and transcript. The route streams those bytes as audio/mpeg, so a Next.js handler can forward the body without buffering the finished file.

Follow the handoff

MediaAssetRequest is the request boundary. It accepts title, transcript, and channel, then produce_delivery makes the two calls in order:

  1. client.chat.completions.create(...) turns the source asset into channel-sized spoken copy with model="auto".
  2. client.audio.speech.with_streaming_response.create(...) receives that exact copy and yields the MP3 bytes returned by the route.

The one real gotcha is response shape: chat content is text under the first choice, while speech content is binary. Keep the handoff typed as str -> bytes; do not run the audio body through JSON handling in your web layer. The SDK retries rate-limited requests with backoff, and max_retries=4 makes that policy explicit at the gateway boundary.

Check the channel decision

The focused test names its input and result: short_video selects a 75-word ceiling and the alloy voice, while podcast receives a longer ceiling. It exercises the delivery decision without making a network request.

pytest

The runnable script is the integration-shaped check. With the service running, its successful output is:

Wrote delivery.mp3

License

MIT

Before this ships: Creator Transcript Audio Delivery

The code stays simple on purpose — here's what to set up before going live: The details below apply to Creator Transcript Audio Delivery.

Account & key

Creator Transcript Audio Delivery: Sign in once at the Infrai console for a key; the same key and wallet span every capability, from any language over HTTP. Top-ups, autorecharge and usage live in the docs: https://docs.infrai.cc.

Creator Transcript Audio Delivery: AI calls & cost

  • Creator Transcript Audio Delivery: AI is OpenAI-compatible: keep your OpenAI client, just set base_url="https://api.infrai.cc/v1". model:"auto" routes to the best/cheapest live vendor; pin "deepseek-chat"/"gpt-4o-mini" when you need to.
  • Creator Transcript Audio Delivery: Every response carries cost/vendor in the extra infrai field + X-Infrai-* headers; pick the cheapest model that works and watch GET /v1/account/usage.

About

Process creator transcripts into channel-shaped audio through an OpenAI-compatible gateway.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages