Skip to main content

TranscriptLine

A single line of transcription representing a phrase or segment of speech.
struct TranscriptLine

Fields

text
std::string
UTF-8 encoded transcription text
startTime
float
Time offset from the start of the audio in seconds
duration
float
Duration of the segment in seconds
lineId
uint64_t
Stable identifier for the line (unique within a session)
isComplete
bool
Whether the line is complete. When true, the text will not change anymore.
isUpdated
bool
Whether the line has been updated since the previous call (streaming only)
isNew
bool
Whether the line was newly added since the previous call (streaming only)
hasTextChanged
bool
Whether the text has changed since the previous call (streaming only)
hasSpeakerId
bool
Whether a speaker ID has been calculated for the line
speakerId
uint64_t
The speaker ID for the line (only valid if hasSpeakerId is true)
speakerIndex
uint32_t
The order the speaker appeared in the current transcript (0-based)
lastTranscriptionLatencyMs
int32_t
The latency of the last transcription operation in milliseconds
audioData
std::vector<float>
Audio data for this line if available (16KHz float PCM, -1.0 to 1.0)

Methods

toString

Returns a string representation of the transcript line.
std::string toString() const
Example:
const TranscriptLine& line = // ... from event

std::cout << "[" << line.startTime << "s] " 
          << line.text << std::endl;
std::cout << "Duration: " << line.duration << "s" << std::endl;
std::cout << "Complete: " << (line.isComplete ? "yes" : "no") 
          << std::endl;

if (line.hasSpeakerId) {
    std::cout << "Speaker " << (line.speakerIndex + 1) << std::endl;
}

// Full details
std::cout << line.toString() << std::endl;

Transcript

A complete transcript containing multiple lines.
struct Transcript

Fields

lines
std::vector<TranscriptLine>
All lines of the transcript in chronological order

Methods

toString

Returns a string representation of the transcript.
std::string toString() const
Example:
Transcript transcript = transcriber.transcribeWithoutStreaming(
    audioData,
    16000
);

for (const auto& line : transcript.lines) {
    std::cout << "[" << line.startTime << "s] " 
              << line.text << std::endl;
}

// Get full text
std::string fullText;
for (const auto& line : transcript.lines) {
    if (!fullText.empty()) {
        fullText += " ";
    }
    fullText += line.text;
}
std::cout << "Full transcript: " << fullText << std::endl;

// Or use toString
std::cout << transcript.toString() << std::endl;

TranscriptEvent (Base Class)

Base class for all transcript events.
class TranscriptEvent

Fields

line
TranscriptLine
The transcript line associated with this event
streamHandle
int32_t
The handle of the stream that emitted this event
type
Type
The type of this event (LINE_STARTED, LINE_UPDATED, LINE_TEXT_CHANGED, LINE_COMPLETED, ERROR)

Event Types

enum Type {
    LINE_STARTED,
    LINE_UPDATED,
    LINE_TEXT_CHANGED,
    LINE_COMPLETED,
    ERROR
}

LineStarted

Event emitted when a new transcription line starts.
class LineStarted : public TranscriptEvent
Example:
void onLineStarted(const LineStarted& event) override {
    std::cout << "New line: " << event.line.text << std::endl;
}

LineUpdated

Event emitted when an existing transcription line is updated.
class LineUpdated : public TranscriptEvent
Example:
void onLineUpdated(const LineUpdated& event) override {
    std::cout << "Updated: " << event.line.text << std::endl;
}

LineTextChanged

Event emitted when the text of a transcription line changes.
class LineTextChanged : public TranscriptEvent
Example:
void onLineTextChanged(const LineTextChanged& event) override {
    // Update UI with new text
    updateDisplay(event.line.text);
}

LineCompleted

Event emitted when a transcription line is completed.
class LineCompleted : public TranscriptEvent
Example:
void onLineCompleted(const LineCompleted& event) override {
    std::cout << "Final: " << event.line.text << std::endl;
    // Save to database, process final result, etc.
}

Error

Event emitted when an error occurs.
class Error : public TranscriptEvent

Additional Fields

errorMessage
std::string
The error message describing what went wrong
Example:
void onError(const Error& event) override {
    std::cerr << "Error: " << event.errorMessage << std::endl;
}

TranscriptEventListener (Abstract Class)

Abstract base class for transcript event listeners.
class TranscriptEventListener

Methods

All methods have default no-op implementations, so you only need to override the ones you care about.
virtual void onLineStarted(const LineStarted& event) {}
virtual void onLineUpdated(const LineUpdated& event) {}
virtual void onLineTextChanged(const LineTextChanged& event) {}
virtual void onLineCompleted(const LineCompleted& event) {}
virtual void onError(const Error& event) {}
Example:
class MyListener : public TranscriptEventListener {
public:
    // Only implement the events you care about
    void onLineTextChanged(const LineTextChanged& event) override {
        std::cout << event.line.text << std::endl;
    }
    
    void onLineCompleted(const LineCompleted& event) override {
        std::cout << "Final: " << event.line.text << std::endl;
    }
};

ModelArch

Model architecture enumeration.
enum class ModelArch

Values

TINY
ModelArch
26 million parameters, smallest model
BASE
ModelArch
58 million parameters, good balance of accuracy and speed
TINY_STREAMING
ModelArch
34 million parameters, streaming variant of tiny
BASE_STREAMING
ModelArch
58 million parameters, streaming variant of base
SMALL_STREAMING
ModelArch
123 million parameters, higher accuracy streaming model
MEDIUM_STREAMING
ModelArch
245 million parameters, highest accuracy streaming model
Example:
Transcriber transcriber(
    "/path/to/models",
    ModelArch::MEDIUM_STREAMING
);

Stream

A stream for real-time transcription with event-based updates.
class Stream

Methods

start

Start the stream.
void start()

stop

Stop the stream and process any remaining audio.
void stop()

addAudio

Add audio data to the stream.
void addAudio(
    const std::vector<float>& audioData,
    int32_t sampleRate = 16000
)

updateTranscription

Manually update the transcription from the stream.
Transcript updateTranscription(uint32_t flags = 0)

addListener (Object-based)

Add a TranscriptEventListener to the stream.
void addListener(TranscriptEventListener* listener)

addListener (Function-based)

Add a function-based event listener to the stream.
void addListener(
    std::function<void(const TranscriptEvent&)> listener
)

removeListener

Remove an event listener from the stream.
void removeListener(TranscriptEventListener* listener)
void removeListener(
    std::function<void(const TranscriptEvent&)> listener
)

removeAllListeners

Remove all event listeners.
void removeAllListeners()

close

Close the stream and free its resources.
void close()

getHandle

Get the stream handle (for internal use).
int32_t getHandle() const

Constants

static const uint32_t FLAG_FORCE_UPDATE = MOONSHINE_FLAG_FORCE_UPDATE;
Example:
Stream stream = transcriber.createStream(0.3);

stream.addListener([](const TranscriptEvent& event) {
    if (event.type == TranscriptEvent::LINE_COMPLETED) {
        const LineCompleted& completed = 
            static_cast<const LineCompleted&>(event);
        std::cout << completed.line.text << std::endl;
    }
});

stream.start();
stream.addAudio(audioData, 16000);
stream.stop();
stream.close();

MoonshineException

Exception class for Moonshine errors.
class MoonshineException : public std::runtime_error
Example:
try {
    Transcriber transcriber("/invalid/path", ModelArch::BASE);
} catch (const MoonshineException& e) {
    std::cerr << "Moonshine error: " << e.what() << std::endl;
} catch (const std::exception& e) {
    std::cerr << "General error: " << e.what() << std::endl;
}

Build docs developers (and LLMs) love