Class ListenBuilder
The shortest useful form
String text = EasyAI.listen().from(audioBytes, "audio/webm");
That is the whole thing. No model builder, no request object, no Base64, no provider name:
the model, key and base URL come from easyai.properties, and — the point worth knowing —
they default to your chat settings. An app that already talks to an OpenAI-compatible
provider for chat gains speech input with no new configuration at all
(see VoiceConfig).
Why this exists at all
Voice should be a new channel into the assistant you already have, not a second brain.
The transcript this returns is ordinary text, so you hand it to the same
assistant — and spoken turns inherit your tools, memory and
context for free. That is also why this class returns a String rather than an answer:
transcribing and deciding are deliberately separate jobs.
Overriding per call
String text = EasyAI.listen()
.withModel("whisper-large-v3") // e.g. when the base URL points at Groq
.withLanguage("sr") // skip language detection
.withEventListener(e -> log.info("{}", e))
.from(audioBytes, "audio/webm");
Analogy: a dictation service. You slide in the recording and get back a typed page. It does not answer the letter — that is the next desk along.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfrom(byte[] audio) Transcribe recorded audio whose MIME type you do not have at hand.Transcribe recorded audio.from(InputStream audio, String mimeType) Transcribe audio read from a stream — the shape a servlet or JAX-RS multipart part gives you.Transcribe an audio file, detecting its MIME type from the file itself.withApiKey(String apiKey) Override the API key for this call (otherwiseeasyai.stt.api-key, theneasyai.api-key).withBaseUrl(String baseUrl) Override the base URL for this call (otherwiseeasyai.stt.base-url, theneasyai.base-url) — this is how you point transcription at any OpenAI-compatible service.withConfig(VoiceConfig config) Replace the whole configuration instead of overriding single values.withEventListener(EasyAIListener eventListener) Register a listener for the liveEasyAIEventstream, so a transcription shows up in your activity timeline like every other EasyAI operation.withLanguage(String language) Tell the model which language to expect, as an ISO-639-1 code (e.g.Name the transcription model for this call.
-
Method Details
-
withConfig
Replace the whole configuration instead of overriding single values.- Parameters:
config- fully built voice settings;nullrestores properties-based defaults- Returns:
- this builder
-
withModel
Name the transcription model for this call.Needed when the base URL points somewhere other than OpenAI — Groq's Whisper is
whisper-large-v3, OpenAI's default isVoiceConfig.DEFAULT_TRANSCRIPTION_MODEL. Nothing is guessed from the URL.- Parameters:
modelName- the provider's model id- Returns:
- this builder
-
withLanguage
Tell the model which language to expect, as an ISO-639-1 code (e.g."sr","en").Leave it unset to let the model detect the language — which is what you want for a bilingual audience, and a real advantage over a browser recognizer pinned to one locale. Set it when you know the language and want the accuracy.
- Parameters:
language- ISO-639-1 language code- Returns:
- this builder
-
withApiKey
Override the API key for this call (otherwiseeasyai.stt.api-key, theneasyai.api-key).- Parameters:
apiKey- the provider API key- Returns:
- this builder
-
withBaseUrl
Override the base URL for this call (otherwiseeasyai.stt.base-url, theneasyai.base-url) — this is how you point transcription at any OpenAI-compatible service.- Parameters:
baseUrl- e.g.https://api.groq.com/openai/v1/- Returns:
- this builder
-
withEventListener
Register a listener for the liveEasyAIEventstream, so a transcription shows up in your activity timeline like every other EasyAI operation.Emits
EasyAIEvent.Phase.STARTEDwhen the call begins andEasyAIEvent.Phase.RESULTcarrying the transcript (orEasyAIEvent.Phase.ERROR), underEasyAIEvent.Source.VOICE. A UI can therefore show what it heard — which is the one thing users most want to verify about a voice interface.- Parameters:
eventListener- the listener (may benullto disable events)- Returns:
- this builder
-
from
Transcribe recorded audio.- Parameters:
audio- the audio bytesmimeType- the audio MIME type, e.g."audio/webm","audio/mpeg"- Returns:
- the recognised text, trimmed (empty if nothing intelligible was heard)
-
from
Transcribe recorded audio whose MIME type you do not have at hand.- Parameters:
audio- the audio bytes- Returns:
- the recognised text
-
from
Transcribe audio read from a stream — the shape a servlet or JAX-RS multipart part gives you.- Parameters:
audio- the stream to read fully (not closed by this method)mimeType- the audio MIME type, e.g. the part's declared type- Returns:
- the recognised text
- Throws:
IllegalStateException- if the stream cannot be read
-
from
Transcribe an audio file, detecting its MIME type from the file itself.- Parameters:
audioFile- path to the recording- Returns:
- the recognised text
- Throws:
IllegalStateException- if the file cannot be read
-