KEPLIN Docs

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.store returns (token, filename, mime and size), ready to save in a record's field. For the bytes, use files.read(r["file"]).
  • size is width x height, for example 1024x1024. With Google, the size becomes the closest aspect ratio (1:1, 3:4, 4:3, 9:16 or 16:9).
  • n generates up to 4 images at once. r["files"] has all of them; r["file"] is the first one.
  • filename is the file name, without extension; without it, the file is called imagem. The extension comes from the image type.
  • If the provider's safety filters block the request, ai.image raises ai.Error with the code invalid_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.store returns.
  • It accepts MP3, MP4, M4A, WAV, WEBM, OGG and FLAC, up to 25 MB (15 MB on Google).
  • language is the spoken language, in two letters (pt, en). Without it, the model identifies it on its own.
  • prompt helps 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 in ai.image. Without filename, the file is called voz.
  • voice is the name of one of the provider's voices, for example alloy or nova at OpenAI and Kore or Puck at Google. Without it, alloy applies in the OpenAI format and Kore at Google.
  • format is mp3 (the default), wav, opus, aac or flac. Google always returns WAV.
  • instructions says 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.