We recently announced our latest speech recognition model, Universal-1, which achieves state-of-the-art speech-to-text accuracy. Trained on millions of hours of audio data, Universal-1 demonstrates near-human accuracy, even with accented speech, background noise, and difficult phrases like flight numbers and email addresses.
Universal-1 is also an order of magnitude faster than our previous model, Conformer-2, and supports English, Spanish, French, and German, with more languages coming shortly.
Along with Universal-1, we’ve also introduced two new classes of models: Best and Nano.
- Best lets you take advantage of Universal-1 for applications where accuracy is paramount.
- Nano is our new cost-effective alternative with support for 99 different languages.
In this post, you’ll learn how to transcribe an audio file in your Java applications using Universal-1 and Nano.
Set up the AssemblyAI Java SDK
The easiest way to transcribe audio is by using one of our official SDKs.
To install the AssemblyAI Java SDK, include the latest version of the SDK in your project dependencies:
Maven:
<dependency>
<groupId>com.assemblyai</groupId>
<artifactId>assemblyai-java</artifactId>
<version>1.0.10</version>
</dependency>
Gradle:
dependencies {
implementation 'com.assemblyai:assemblyai-java:1.0.10'
}
Then import the SDK namespaces in your Java code.
import com.assemblyai.api.AssemblyAI;
import com.assemblyai.api.resources.transcripts.types.SpeechModel;
import com.assemblyai.api.resources.transcripts.types.Transcript;
import com.assemblyai.api.resources.transcripts.types.TranscriptOptionalParams;
Configure a new authenticated SDK client using your AssemblyAI API key from your account dashboard.
var client = AssemblyAI.builder()
.apiKey(System.getenv("ASSEMBLYAI_API_KEY"))
.build();
You’ll find all the operations you need on the AssemblyAI
instance.
Transcribe an audio file using Universal-1
All transcriptions use the Best class of models by default, so you’ll always get the highest accuracy without any extra configuration.
Use the following code to transcribe an audio file from a URL using Best:
Transcript transcript = client.transcripts().transcribe(
"https://storage.googleapis.com/aai-web-samples/5_common_sports_injuries.mp3"
);
if (transcript.getStatus().equals(TranscriptStatus.ERROR)) {
throw new Exception(transcript.getError().get());
}
System.out.println(transcript.getText().get());
If you instead want to transcribe a local file, create a File
object pointing to the path of the file to transcribe:
Transcript transcript = client.transcripts().transcribe(
new File("./audio.mp3")
);
Nano—a cost-effective alternative
Switching between Best and Nano is only a matter of setting the speech model parameter in the parameters builder. To use Nano, set the speechModel(...)
to SpeechModel.NANO
:
Transcript transcript = client.transcripts().transcribe(
"https://storage.googleapis.com/aai-web-samples/5_common_sports_injuries.mp3",
TranscriptOptionalParams.builder()
.speechModel(SpeechModel.NANO)
.build()
);
Best, Nano and More with Audio Intelligence
We just used Universal-1 through both the Best and Nano class of models to transcribe audio.
Next, there are many further features that AssemblyAI offers beyond transcription to explore, such as:
- Entity detection to automatically identify and categorize key information.
- Content moderation for detecting inappropriate content in audio files to ensure that your content is safe for all audiences.
- PII redaction to minimize sensitive information about individuals by automatically identifying and removing it from your transcript.
- LeMUR for applying Large Language Models (LLMs) to audio data in a single line of code.
You can also learn more about our approach to creating superhuman Speech AI models on our Research page.