AIU. - Artificial Intelligence Utility

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > AI - Artificial Intelligence Commands > AIU. - OpenAI API > !Core Operations >

AIU. - Artificial Intelligence Utility

AIU.TextToSpeech

Previous Top Next


MiniRobotLanguage (MRL)

 

AIU.TextToSpeech
Synthesizes speech from text and saves it to an audio file.

 

Intention

 

The AIU.TextToSpeech command (aliased as AIU.Tts) converts written text into natural-sounding spoken audio. It sends the text to an OpenAI Text-to-Speech (TTS) model and saves the resulting audio data to a specified file path (e.g., as an MP3). This allows your robot to generate voice responses, read text aloud, or create audio notifications.

 

It’s your robot’s voice—AIU.TextToSpeech takes text and speaks it into an audio file.

 

Illustration

 

┌───────────────────────────┐

│ Text Input                │

├───────────────────────────┤

│ "Hello, world."           │

├──────────────┬────────────┤

│ AI TTS       │ Result     │

├──────────────┼────────────┤

│ Synthesizes… │ audio.mp3  │

└──────────────┴────────────┘

Converting text into a spoken audio file.

 

Syntax

 

AIU.TextToSpeech|$$TXT|$$PTH

 

Parameter Explanation

 

P1 - $$TXT - (Variable, String, Required)

The text to be synthesized into speech.

 

P2 - $$PTH - (Variable, String, Required)

The variable that will receive the full path to the generated audio file on success.

 

Examples

 

'***********************************

' AIU.TextToSpeech - Sample 1: Basic Speech Synthesis

'***********************************

VAR.$$KEY=sk-YourSecretKeyHere

AIU.SetKey|$$KEY

 

VAR.$$TXT=Hello from MiniRobot! I can now speak.

AIU.TextToSpeech|$$TXT|$$PTH

 

' Check for errors

AIU.GetLastError|$$ERR

JNZ.$$ERR|Lab_failed

 

MBX.Success:|Audio file created at:$$crlf$$PTH

END.

 

 

Remarks

 

- The alias AIU.Tts can be used for convenience.

- The AI model and voice can be changed using AIU.SetTtsModel and AIU.SetTtsVoice.

- The output file is typically an MP3. The command returns the full path to the saved file.

- On failure, an error is set which can be retrieved with AIU.GetLastError and AIU.GetLastErrorMsg.

 

See also:

 

AIU.SpeechToText

AIU.SetTtsModel

AIU.SetTtsVoice