• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
larryhudson

larryhudson

saveTextToPodcast

Public
Like
5
saveTextToPodcast
Home
Code
3
README.md
H
index.ts
test.html
Branches
1
Pull requests
Remixes
History
Environment variables
3
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
7/6/2025
Viewing readonly version of main branch: v4
View latest version
README.md

Text-to-Speech API

This HTTP Val converts text files to speech using OpenAI's TTS API and stores the results for podcast generation.

Setup

  1. Set the OPENAI_API_KEY environment variable in your Val Town settings
  2. The SQLite database table will be created automatically on first use

API Endpoints

POST /convert

Converts a text file to speech and stores it.

Parameters:

  • file (File): Text file to convert
  • name (string): Name/title for the episode

Example using curl:

curl -X POST https://your-val-url.web.val.run/convert \ -F "file=@your-text-file.txt" \ -F "name=My First Episode"

Response:

{ "success": true, "message": "Text converted to speech successfully", "data": { "name": "My First Episode", "mp3_url": "https://your-val-url.web.val.run/audio/tts_1234567890.mp3", "text_length": 1250 } }

GET /audio/:filename

Serves MP3 audio files from storage.

GET /episodes

Lists all converted episodes.

Response:

{ "success": true, "episodes": [ { "id": 1, "name": "My First Episode", "text": "This is the text content...", "mp3_url": "https://your-val-url.web.val.run/audio/tts_1234567890.mp3", "date_added": "2024-01-01 12:00:00" } ] }

GET /podcast.xml

Generates an RSS podcast feed from all episodes.

Database Schema

The tts_episodes table contains:

  • id (INTEGER PRIMARY KEY)
  • name (TEXT) - Episode title
  • text (TEXT) - Original text content
  • mp3_url (TEXT) - URL to the MP3 file
  • date_added (DATETIME) - Timestamp when added

Features

  • ✅ Text file upload and conversion to MP3
  • ✅ SQLite database storage
  • ✅ MP3 file serving from blob storage
  • ✅ RSS podcast feed generation
  • ✅ Error handling and validation
  • ✅ Automatic database initialization

Usage Notes

  • Uses OpenAI's tts-1 model with the alloy voice
  • MP3 files are stored in Val Town's blob storage
  • Database records include full text content for search/reference
  • Podcast feed is automatically generated from database records
  • All endpoints include proper error handling
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.