Images and audio
Generating images with ai.image, transcribing recordings with ai.transcribe and generating speech with ai.speak.
Each operation uses an alias of the right use: Images for ai.image,
Transcription for ai.transcribe and Speech for ai.speak. Without
model=, that use's default alias applies. Not every provider does these
operations: see What each provider does.
Generating images
from api_manager import ai
def main(input):
r = ai.image(
"Fotografia de produto de uma cadeira de madeira, fundo branco",
size="1024x1024",
filename="cadeira",
)
return {"ficheiro": r["file"]} # {"token", "filename", "mime", "size"}
- The images go straight to the app's storage. Each one comes as the file
that
files.storereturns (token,filename,mimeandsize), ready to save in a record's field. For the bytes, usefiles.read(r["file"]). sizeis width x height, for example1024x1024. With Google, the size becomes the closest aspect ratio (1:1, 3:4, 4:3, 9:16 or 16:9).ngenerates up to 4 images at once.r["files"]has all of them;r["file"]is the first one.filenameis the file name, without extension; without it, the file is calledimagem. The extension comes from the image type.- If the provider's safety filters block the request,
ai.imageraisesai.Errorwith the codeinvalid_output.
Transcribing audio
from api_manager import ai
def main(input):
gravacao = input["args"]["gravacao"] # an Upload argument of an API
t = ai.transcribe(gravacao, language="pt", prompt="Keplin, Gestão de Clientes")
return {"texto": t["text"]}
- The file is an Upload argument, its token, or what
files.storereturns. - It accepts MP3, MP4, M4A, WAV, WEBM, OGG and FLAC, up to 25 MB (15 MB on Google).
languageis the spoken language, in two letters (pt,en). Without it, the model identifies it on its own.prompthelps with proper names, acronyms and technical terms that appear in the recording.
Generating speech
from api_manager import ai
def main(input):
voz = ai.speak("A sua encomenda já saiu do armazém.", voice="alloy", filename="aviso")
return {"ficheiro": voz["file"]}
- The audio goes to the app's storage, and
voz["file"]is the file, as inai.image. Withoutfilename, the file is calledvoz. voiceis the name of one of the provider's voices, for examplealloyornovaat OpenAI andKoreorPuckat Google. Without it,alloyapplies in the OpenAI format andKoreat Google.formatismp3(the default),wav,opus,aacorflac. Google always returns WAV.instructionssays how to speak (tone, pace, emotion), in the models that accept it.
Frequently asked questions
Can I edit an existing image? No: ai.image generates new images from
text. To describe or analyse an image, use ai.chat with files=.
Can I translate a recording? Transcribe it with ai.transcribe and
translate the text with ai.chat.