Transcribe an audio file with Universal-1 utilizing Go

Transcribe an audio file with Universal-1 utilizing Go

Transcribe an audio file with Universal-1 using Go

We lately introduced our newest speech mannequin, Universal-1, which units a brand new commonplace for speech-to-text accuracy. Trained on hundreds of thousands of hours of audio information, Universal-1 demonstrates near-human accuracy, even with accented speech, background noise, and troublesome phrases like flight numbers and e-mail addresses.

Universal-1 can be an order of magnitude quicker than our earlier mannequin, Conformer-2, and helps English, Spanish, French, and German, with extra languages coming shortly.

Along with Universal-1, we’ve additionally launched two new pricing tiers: Best and Nano.

  • Best enables you to make the most of Universal-1 for functions the place accuracy is paramount.
  • Nano is our new cost-effective tier with help for 99 completely different languages.

In this publish, you’ll discover ways to transcribe an audio file in your Go functions utilizing Universal-1 and Nano.

Set up the AssemblyAI Go SDK

The best strategy to begin transcribing audio is by utilizing one among our official SDKs.

To set up the AssemblyAI Go SDK, run the next command in the identical listing as your Go challenge:

go get github.com/AssemblyAI/assemblyai-go-sdk

Import the Go module in your challenge:

import (
	aai "github.com/AssemblyAI/assemblyai-go-sdk"
)

Configure a brand new authenticated SDK shopper utilizing your API key out of your account dashboard.

apiKey := os.Getenv("ASSEMBLYAI_API_KEY")

shopper := aai.NewClient(apiKey)

You’ll discover all of the operations you want on the shopper occasion, such because the TranscribeFromURL and TranscribeFromReader.

Transcribe an audio file utilizing Universal-1

By default, all transcriptions use the Best tier, so that you’ll at all times get the best accuracy with none further configuration.

To transcribe an audio file from a URL utilizing Best tier, create a brand new file known as most important.go with the next code:

package deal most important

import (
	"context"
	"fmt"
	"os"

	aai "github.com/AssemblyAI/assemblyai-go-sdk"
)

func most important() {
	apiKey := os.Getenv("ASSEMBLYAI_API_KEY")

	shopper := aai.NewClient(apiKey)

	ctx := context.Background()

	audioURL := "https://storage.googleapis.com/aai-web-samples/5_common_sports_injuries.mp3"

	params := &aai.TranscriptOptionalParams{}

	transcript, err := shopper.Transcripts.TranscribeFromURL(ctx, audioURL, params)
	if err != nil {
		fmt.Println("Something went mistaken whereas transcribing:", err)
		os.Exit(1)
	}

	fmt.Println(aai.ToString(transcript.Text))
}

If you as an alternative wish to transcribe a neighborhood file, use TranscribeFromReader:

package deal most important

import (
	"context"
	"fmt"
	"os"

	aai "github.com/AssemblyAI/assemblyai-go-sdk"
)

func most important() {
	apiKey := os.Getenv("ASSEMBLYAI_API_KEY")

	shopper := aai.NewClient(apiKey)

	ctx := context.Background()

	f, err := os.Open("./audio.mp3")
	if err != nil {
		fmt.Println("Something went mistaken whereas opening the file:", err)
		os.Exit(1)
	}
	defer f.Close()

	params := &aai.TranscriptOptionalParams{}

	transcript, err := shopper.Transcripts.TranscribeFromReader(ctx, f, params)
	if err != nil {
		fmt.Println("Something went mistaken whereas transcribing:", err)
		os.Exit(1)
	}

	fmt.Println(aai.ToString(transcript.Text))
}

Nano—a cheap speech-to-text various

Switching between Best and Nano is just a matter of setting SpeechModel in your transcription parameters.

params := &aai.TranscriptOptionalParams{
	SpeechModel: aai.SpeechModelNano,
}

Best or Nano, which one is best for you?

With two speech-to-text choices, you may marvel which one it’s best to use on your utility.

We advocate utilizing Best for functions the place it’s vital to get correct, high-quality transcripts—for instance, if you wish to show the transcript to your finish consumer.

If you have got high-volume transcriptions and trying to cut back prices, or should you want extra language help, we encourage you to attempt Nano.

We encourage you to check the outcomes to seek out which one works finest for the appliance you’re constructing.

To learn extra about Universal-1, see our analysis article.

HI-FI News

by way of News, Tutorials, AI Research https://ift.tt/6R3xMh5

April 4, 2024 at 05:52PM