The official Go SDK for interacting with Camb.ai's powerful voice and audio generation APIs. Create expressive speech, unique voices, and rich soundscapes with idiomatic Go.
- Dubbing: End-to-end video dubbing and translation.
- Expressive Text-to-Speech: High-fidelity speech synthesis with standard and custom voices.
- Generative Voices: Create entirely new voices from text descriptions.
- Voice Cloning: Clone voices from audio samples.
- Soundscapes: Generate ambient audio and sound effects.
go get github.com/camb-ai/cambai-go-sdkInitialize the client with your API key. You can pass it directly or load it from an environment variable.
import (
"os"
"github.com/camb-ai/cambai-go-sdk/client"
"github.com/camb-ai/cambai-go-sdk/option"
)
func main() {
c := client.NewClient(
option.WithAPIKey(os.Getenv("CAMB_API_KEY")),
)
}| Model Name | Sample Rate | Description |
|---|---|---|
| mars-pro | 48kHz | High-fidelity, professional-grade speech synthesis. Ideal for long-form content and dubbing. |
| mars-instruct | 22.05kHz | Optimized for instruction-following and nuance control. |
| mars-flash | 22.05kHz | Low-latency model optimized for real-time applications and conversational AI. |
Generate and stream speech in real-time. This example uses the high-fidelity mars-pro model.
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/camb-ai/cambai-go-sdk"
"github.com/camb-ai/cambai-go-sdk/client"
"github.com/camb-ai/cambai-go-sdk/option"
)
func main() {
c := client.NewClient(option.WithAPIKey(os.Getenv("CAMB_API_KEY")))
fmt.Println("Streaming TTS...")
resp, err := c.TextToSpeech.Tts(
context.Background(),
&cambai.CreateStreamTtsRequestPayload{
Text: "Hello from Camb AI Go SDK!",
VoiceID: 20303,
Language: cambai.CreateStreamTtsRequestPayloadLanguageEnUs,
SpeechModel: cambai.CreateStreamTtsRequestPayloadSpeechModelMarsPro.Ptr(),
OutputConfiguration: &cambai.StreamTtsOutputConfiguration{
Format: cambai.OutputFormatWav.Ptr(),
},
},
)
if err != nil {
panic(err)
}
out, _ := os.Create("tts_output.wav")
defer out.Close()
io.Copy(out, resp)
fmt.Println("✓ Success! Audio saved to tts_output.wav")
}Dub a video from one language to another and poll for the result.
package main
import (
"context"
"fmt"
"time"
"github.com/camb-ai/cambai-go-sdk"
"github.com/camb-ai/cambai-go-sdk/client"
"github.com/camb-ai/cambai-go-sdk/option"
)
func main() {
c := client.NewClient(option.WithAPIKey(os.Getenv("CAMB_API_KEY")))
resp, _ := c.Dub.EndToEndDubbing(
context.Background(),
&cambai.EndToEndDubbingRequestPayload{
VideoURL: "https://example.com/video.mp4",
SourceLanguage: cambai.LanguagesEnUs,
TargetLanguages: []cambai.Languages{cambai.LanguagesHiIn},
},
)
taskID := *resp.TaskID
fmt.Printf("Dubbing started. Task ID: %s\n", taskID)
for {
time.Sleep(5 * time.Second)
statusResp, _ := c.Dub.GetEndToEndDubbingStatus(context.Background(), taskID, nil)
if statusResp.Status == cambai.TaskStatusSuccess {
runID := *statusResp.RunID
result, _ := c.Dub.GetDubbedRunInfo(context.Background(), &runID, nil)
if result.DubbingResult != nil {
fmt.Printf("✓ Dubbing successful! Video URL: %s\n", *result.DubbingResult.VideoURL)
fmt.Printf(" Transcript: %v\n", result.DubbingResult.Transcript)
}
break
} else if statusResp.Status == cambai.TaskStatusError {
fmt.Println("Dubbing failed.")
break
}
}
}Create a unique new voice from a description.
resp, _ := c.TextToVoice.CreateTextToVoice(
context.Background(),
&cambai.CreateTextToVoiceRequestPayload{
Text: "Crafting a truly unique and captivating voice.",
VoiceDescription: "A smooth, rich baritone voice layered with warmth.",
},
)
taskID := *resp.TaskID
fmt.Printf("Voice generation task created: %s\n", taskID)
// Poll status using c.TextToVoice.GetTextToVoiceStatus(taskID)Generate sound effects from a descriptive prompt.
resp, _ := c.TextToAudio.CreateTextToAudio(
context.Background(),
&cambai.CreateTextToAudioRequestPayload{
Prompt: "A gentle breeze rustling through autumn leaves.",
Duration: cambai.Float64(3.0),
AudioType: cambai.String("sound"),
},
)
taskID := *resp.TaskID
fmt.Printf("Sound task created: %s\n", taskID)
// Poll status and get result run_id, then download using c.TextToAudio.GetTextToAudioResult(run_id)The Camb AI SDK offers a wide range of capabilities beyond these examples, including:
- Voice Cloning
- Translated TTS
- Audio Dubbing
- Transcription
- And more!
Please refer to the Official Camb AI API Documentation for a comprehensive list of features and advanced usage patterns.
Check out the examples/ directory for complete, runnable examples:
examples/basic-tts- Basic text-to-speech exampleexamples/text-to-audio- Sound generation exampleexamples/dubbing- Video dubbing workflowexamples/baseten-provider- Using custom hosting providers
This project is licensed under the MIT License - see the LICENSE file for details
