Skip to content

Add Go API for Cohere Transcribe - #3466

Merged
csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:go-api
Apr 3, 2026
Merged

csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:go-api

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Apr 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Cohere Transcribe support for offline audio transcription with configurable models and text normalization options
  • Tests

    • Added continuous integration pipeline to validate Cohere Transcribe decoding functionality with automated model downloading

csukuangfj and others added 2 commits April 2, 2026 17:38
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 3, 2026
@coderabbitai

coderabbitai Bot commented Apr 3, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fee35af9-25e7-4593-a3e1-c7f017d1e034

📥 Commits

Reviewing files that changed from the base of the PR and between bc3312a and 7712f7d.

📒 Files selected for processing (8)
  • .github/workflows/test-go.yaml
  • go-api-examples/non-streaming-cohere-transcribe-decode-files/go.mod
  • go-api-examples/non-streaming-cohere-transcribe-decode-files/main.go
  • go-api-examples/non-streaming-cohere-transcribe-decode-files/run.sh
  • scripts/go/_internal/non-streaming-cohere-transcribe-decode-files/go.mod
  • scripts/go/_internal/non-streaming-cohere-transcribe-decode-files/main.go
  • scripts/go/_internal/non-streaming-cohere-transcribe-decode-files/run.sh
  • scripts/go/sherpa_onnx.go

📝 Walkthrough

Walkthrough

This PR adds Cohere Transcribe offline transcription support to the Go language bindings for sherpa-onnx. It introduces a new Go example application, CI test infrastructure, module configurations, and extends the core Go bindings with CohereTranscribe model configuration structures.

Changes

Cohort / File(s) Summary
CI/Workflow Integration
.github/workflows/test-go.yaml
Added new CI step to run Go-based non-streaming Cohere Transcribe decoding tests, including directory operations, dependency management, and binary execution; extended Windows DLL deployment to copy required native libraries to the test directory.
Go Example Application
go-api-examples/non-streaming-cohere-transcribe-decode-files/main.go, go-api-examples/non-streaming-cohere-transcribe-decode-files/go.mod, go-api-examples/non-streaming-cohere-transcribe-decode-files/run.sh
New complete Go application for non-streaming Cohere Transcribe audio decoding with ONNX model configuration, includes module declaration, shell script for model download and build automation, and main program logic for WAV file transcription.
Internal Test Script Pointers
scripts/go/_internal/non-streaming-cohere-transcribe-decode-files/main.go, scripts/go/_internal/non-streaming-cohere-transcribe-decode-files/run.sh, scripts/go/_internal/non-streaming-cohere-transcribe-decode-files/go.mod
New test infrastructure that references corresponding go-api-examples scripts; module configuration redirects sherpa-onnx dependency to local relative directory for testing.
Core Go Bindings
scripts/go/sherpa_onnx.go
Added new OfflineCohereTranscribeModelConfig struct with encoder/decoder paths and configuration flags; extended OfflineModelConfig with CohereTranscribe field; updated C config population and cleanup functions to wire new fields into underlying C structures.

Sequence Diagram

sequenceDiagram
    participant App as Go Application
    participant Lib as sherpa-onnx Go Lib
    participant C as C/C++ Backend
    participant Model as ONNX Model

    App->>Lib: Create OfflineRecognizerConfig<br/>(with CohereTranscribeModelConfig)
    Lib->>C: newCOfflineRecognizerConfig<br/>(populate cohere_transcribe fields)
    App->>Lib: Initialize OfflineRecognizer
    Lib->>Model: Load encoder/decoder ONNX
    Model-->>Lib: Models loaded
    Lib-->>App: Recognizer ready
    App->>Lib: Create OfflineStream
    Lib-->>App: Stream created
    App->>Lib: AcceptWaveform(samples, sample_rate)
    Lib->>C: Feed audio to recognizer
    App->>Lib: Decode(stream)
    C->>Model: Run ONNX inference
    Model-->>C: Transcription output
    Lib->>Lib: GetResult()
    Lib-->>App: Return transcribed text
    App->>Lib: Cleanup (defer)
    Lib->>C: freeCOfflineRecognizerConfig<br/>(free cohere_transcribe strings)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • k2-fsa/sherpa-onnx#3462: Adds CohereTranscribe model config to C# language bindings with identical struct and field wiring pattern.
  • k2-fsa/sherpa-onnx#3460: Adds Cohere Transcribe offline transcription support to Swift bindings and example applications.
  • k2-fsa/sherpa-onnx#3457: Modifies C/C++ core APIs to introduce CohereTranscribe configuration structures that the Go bindings depend on.

Suggested labels

size:M

Poem

🐰 A rabbit hops through model paths,
With Cohere's transcribe on our graphs,
Go bindings wired, examples set,
Audio streams we won't forget—
Transcription dreams in code, you bet!

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@csukuangfj
csukuangfj merged commit 3fabf52 into k2-fsa:master Apr 3, 2026
1 check was pending
@csukuangfj
csukuangfj deleted the go-api branch April 3, 2026 03:38

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the Cohere Transcribe model to the Go API, including the necessary configuration structures and C-binding updates. It also introduces a new example for non-streaming transcription. The review feedback highlights several critical issues: a potential nil pointer dereference when accessing transcription results, an incorrect relative path in a go.mod file, and files in the internal directory that appear to be broken symbolic links. Additionally, it is suggested to set the language parameter within the configuration struct rather than via stream options for better consistency with the library's design.

Comment on lines +42 to +44
result := stream.GetResult()

log.Println("Text: " + strings.ToLower(result.Text))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

stream.GetResult() can return nil if no recognition result is available (e.g., if the audio is empty or decoding fails). Accessing result.Text without a nil check will cause a runtime panic. Additionally, using strings.ToLower on the output is generally discouraged for examples as it discards the formatting (casing) provided by the model when UsePunct is enabled.

	result := stream.GetResult()
	if result != nil {
		log.Println("Text: " + result.Text)
	}


go 1.17

replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The relative path in the replace directive is incorrect. The sherpa_onnx package is located in scripts/go/, which is two levels up from this directory (../../), not one level (../).

Suggested change
replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../
replace github.com/k2-fsa/sherpa-onnx-go/sherpa_onnx => ../../

@@ -0,0 +1 @@
../../../../go-api-examples/non-streaming-cohere-transcribe-decode-files/main.go No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This file contains a relative path string instead of valid Go source code. It appears that a symbolic link was intended but was committed as a regular text file. This will cause the Go compiler to fail in this directory.

@@ -0,0 +1 @@
../../../../go-api-examples/non-streaming-cohere-transcribe-decode-files/run.sh No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This file contains a relative path string instead of a valid shell script. It appears that a symbolic link was intended but was committed as a regular text file.

stream := sherpa.NewOfflineStream(recognizer)
defer sherpa.DeleteOfflineStream(stream)

stream.SetOption("language", "en")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The OfflineCohereTranscribeModelConfig struct (defined in sherpa_onnx.go) includes a Language field. It is more consistent with the design of this library to set the language in the configuration during initialization rather than using stream.SetOption("language", "en") on the stream, especially for offline models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant