TranscriptLine
A single line of transcription representing a phrase or segment of speech.
public class TranscriptLine
Fields
UTF-8 encoded transcription text
Audio data for this line if available (16KHz float PCM, -1.0 to 1.0)
Time offset from the start of the audio in seconds
Duration of the segment in seconds
Stable identifier for the line (unique within a session)
Whether the line is complete. When true, the text will not change anymore.
Whether the line has been updated since the previous call (streaming only)
Whether the line was newly added since the previous call (streaming only)
Whether the text has changed since the previous call (streaming only)
Whether a speaker ID has been calculated for the line
The speaker ID for the line (only valid if hasSpeakerId is true)
The order the speaker appeared in the current transcript (0-based)
lastTranscriptionLatencyMs
The latency of the last transcription operation in milliseconds
Methods
toString
Returns a string representation of the transcript line.
Example:
TranscriptLine line = // ... from event
System.out.println("[" + line.startTime + "s] " + line.text);
System.out.println("Duration: " + line.duration + "s");
System.out.println("Complete: " + line.isComplete);
if (line.hasSpeakerId) {
System.out.println("Speaker " + (line.speakerIndex + 1));
}
// Full details
System.out.println(line.toString());
Transcript
A complete transcript containing multiple lines.
Fields
Array of all lines in the transcript in chronological order
Example:
Transcript transcript = transcriber.transcribeWithoutStreaming(
audioData,
16000
);
for (TranscriptLine line : transcript.lines) {
System.out.println("[" + line.startTime + "s] " + line.text);
}
// Get full text
StringBuilder fullText = new StringBuilder();
for (TranscriptLine line : transcript.lines) {
if (fullText.length() > 0) {
fullText.append(" ");
}
fullText.append(line.text);
}
System.out.println("Full transcript: " + fullText.toString());
TranscriptEvent (Interface)
Base interface for all transcript events. Uses the Visitor pattern for type-safe event handling.
public interface TranscriptEvent
Methods
accept
Accept a visitor to handle this event.
void accept(Visitor visitor)
Visitor Interface
Interface for handling different event types.
interface Visitor {
void onLineStarted(LineStarted event);
void onLineUpdated(LineUpdated event);
void onLineTextChanged(LineTextChanged event);
void onLineCompleted(LineCompleted event);
void onError(Error event);
}
Example:
transcriber.addListener(event -> {
event.accept(new TranscriptEvent.Visitor() {
@Override
public void onLineStarted(TranscriptEvent.LineStarted e) {
// Handle line started
}
@Override
public void onLineUpdated(TranscriptEvent.LineUpdated e) {
// Handle line updated
}
@Override
public void onLineTextChanged(TranscriptEvent.LineTextChanged e) {
// Handle text changed
}
@Override
public void onLineCompleted(TranscriptEvent.LineCompleted e) {
// Handle line completed
}
@Override
public void onError(TranscriptEvent.Error e) {
// Handle error
}
});
});
TranscriptEvent.LineStarted
Event emitted when a new transcription line starts.
class LineStarted implements TranscriptEvent
Fields
The transcript line associated with this event
The handle of the stream that emitted this event
Example:
@Override
public void onLineStarted(TranscriptEvent.LineStarted event) {
System.out.println("New line: " + event.line.text);
}
TranscriptEvent.LineUpdated
Event emitted when an existing transcription line is updated.
class LineUpdated implements TranscriptEvent
Fields
The transcript line associated with this event
The handle of the stream that emitted this event
Example:
@Override
public void onLineUpdated(TranscriptEvent.LineUpdated event) {
System.out.println("Updated: " + event.line.text);
}
TranscriptEvent.LineTextChanged
Event emitted when the text of a transcription line changes.
class LineTextChanged implements TranscriptEvent
Fields
The transcript line associated with this event
The handle of the stream that emitted this event
Example:
@Override
public void onLineTextChanged(TranscriptEvent.LineTextChanged event) {
// Update UI with new text
runOnUiThread(() -> {
textView.setText(event.line.text);
});
}
TranscriptEvent.LineCompleted
Event emitted when a transcription line is completed.
class LineCompleted implements TranscriptEvent
Fields
The transcript line associated with this event
The handle of the stream that emitted this event
Example:
@Override
public void onLineCompleted(TranscriptEvent.LineCompleted event) {
System.out.println("Final: " + event.line.text);
// Save to database, process final result, etc.
}
TranscriptEvent.Error
Event emitted when an error occurs.
class Error implements TranscriptEvent
Fields
The throwable that caused the error
The handle of the stream that emitted this event
Example:
@Override
public void onError(TranscriptEvent.Error event) {
System.err.println("Error: " + event.cause.getMessage());
event.cause.printStackTrace();
}
Model Architecture Constants
Model architecture constants are defined in the JNI class:
public class JNI {
public static final int MOONSHINE_MODEL_ARCH_TINY = 0;
public static final int MOONSHINE_MODEL_ARCH_BASE = 1;
public static final int MOONSHINE_MODEL_ARCH_TINY_STREAMING = 2;
public static final int MOONSHINE_MODEL_ARCH_BASE_STREAMING = 3;
public static final int MOONSHINE_MODEL_ARCH_SMALL_STREAMING = 4;
public static final int MOONSHINE_MODEL_ARCH_MEDIUM_STREAMING = 5;
public static final int MOONSHINE_FLAG_FORCE_UPDATE = 1;
}
Example:
import ai.moonshine.voice.JNI;
// Use model architecture constants
transcriber.loadFromFiles(
modelPath,
JNI.MOONSHINE_MODEL_ARCH_MEDIUM_STREAMING
);
Helper Classes
TranscriberOption
Represents a configuration option for the transcriber.
public class TranscriberOption {
public String key;
public String value;
public TranscriberOption(String key, String value) {
this.key = key;
this.value = value;
}
}
Example:
import ai.moonshine.voice.TranscriberOption;
import java.util.ArrayList;
import java.util.List;
List<TranscriberOption> options = new ArrayList<>();
options.add(new TranscriberOption("max_tokens_per_second", "13.0"));
Transcriber transcriber = new Transcriber(options);