tts.php
Table of Contents
Functions
- tts_sanitizeLang() : string
- Normalize and whitelist a TTS locale tag, falling back to fr-FR when invalid.
- tts_buildEspeakCmd() : string
- Build a shell-safe espeak pipeline that renders text to an MP3 file.
- tts_buildPicoCmd() : string
- Build a shell-safe pico2wave + transcode pipeline that renders text to an MP3 file with volume adjustment.
Functions
tts_sanitizeLang()
Normalize and whitelist a TTS locale tag, falling back to fr-FR when invalid.
tts_sanitizeLang(string $_lang) : string
Parameters
- $_lang : string
-
Locale tag (e.g. "fr_FR", "en-US").
Return values
string —Normalized locale tag with a hyphen separator, or "fr-FR" if the input does not match the expected shape.
tts_buildEspeakCmd()
Build a shell-safe espeak pipeline that renders text to an MP3 file.
tts_buildEspeakCmd(string $_text, string $_voice, string $_filename[, string $_avconv = 'ffmpeg' ]) : string
Parameters
- $_text : string
-
Text to synthesize.
- $_voice : string
-
espeak voice identifier.
- $_filename : string
-
Destination MP3 path.
- $_avconv : string = 'ffmpeg'
-
Transcoder binary name (defaults to "ffmpeg"). Must be a trusted constant, not user input.
Return values
string —Full shell command, ready for exec/shell_exec.
tts_buildPicoCmd()
Build a shell-safe pico2wave + transcode pipeline that renders text to an MP3 file with volume adjustment.
tts_buildPicoCmd(string $_text, string $_lang, string $_volume, string $_md5, string $_filename[, string $_avconv = 'ffmpeg' ]) : string
Parameters
- $_text : string
-
Text to synthesize.
- $_lang : string
-
Locale tag, sanitized through tts_sanitizeLang().
- $_volume : string
-
Volume adjustment in dB, cast through floatval().
- $_md5 : string
-
Unique identifier used to name the intermediate WAV file.
- $_filename : string
-
Destination MP3 path.
- $_avconv : string = 'ffmpeg'
-
Transcoder binary name (defaults to "ffmpeg"). Must be a trusted constant, not user input.
Tags
Return values
string —Full shell command, ready for exec/shell_exec.