Wednesday, February 4, 2026
No Result
View All Result
The Crypto HODL
  • Home
  • Bitcoin
  • Crypto Updates
    • Altcoin
    • Ethereum
    • Crypto Updates
    • Crypto Mining
    • Crypto Exchanges
  • Blockchain
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Regulations
  • Scam Alert
  • Analysis
  • Videos
Marketcap
  • Home
  • Bitcoin
  • Crypto Updates
    • Altcoin
    • Ethereum
    • Crypto Updates
    • Crypto Mining
    • Crypto Exchanges
  • Blockchain
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Regulations
  • Scam Alert
  • Analysis
  • Videos
No Result
View All Result
The Crypto HODL
No Result
View All Result

Building Real-Time Language Translation with AssemblyAI and DeepL in JavaScript

July 14, 2024
in Blockchain
Reading Time: 4 mins read
0 0
A A
0
Home Blockchain
Share on FacebookShare on Twitter




Ted Hisokawa
Jul 14, 2024 05:20

Discover ways to create a real-time language translation service utilizing AssemblyAI and DeepL in JavaScript. Step-by-step information for builders.





In a complete tutorial, AssemblyAI provides insights into making a real-time language translation service utilizing JavaScript. The tutorial leverages AssemblyAI for real-time speech-to-text transcription and DeepL for translating the transcribed textual content into numerous languages.

Introduction to Actual-Time Translation

Translations play a crucial function in communication and accessibility throughout completely different languages. As an illustration, a vacationer abroad might wrestle to speak if they do not perceive the native language. AssemblyAI’s Streaming Speech-to-Textual content service can transcribe speech in real-time, which might then be translated utilizing DeepL, making communication seamless.

Setting Up the Undertaking

The tutorial begins with establishing a Node.js challenge. Important dependencies are put in, together with Categorical.js for making a easy server, dotenv for managing atmosphere variables, and the official libraries for AssemblyAI and DeepL.

mkdir real-time-translation
cd real-time-translation
npm init -y
npm set up categorical dotenv assemblyai deepl-node

API keys for AssemblyAI and DeepL are saved in a .env file to maintain them safe and keep away from exposing them within the frontend.

Creating the Backend

The backend is designed to maintain API keys safe and generate momentary tokens for safe communication with the AssemblyAI and DeepL APIs. Routes are outlined to serve the frontend and deal with token technology and textual content translation.

const categorical = require(“categorical”);
const deepl = require(“deepl-node”);
const { AssemblyAI } = require(“assemblyai”);
require(“dotenv”).config();

const app = categorical();
const port = 3000;

app.use(categorical.static(“public”));
app.use(categorical.json());

app.get(“https://blockchain.information/”, (req, res) => {
res.sendFile(__dirname + “/public/index.html”);
});

app.get(“/token”, async (req, res) => {
const token = await consumer.realtime.createTemporaryToken({ expires_in: 300 });
res.json({ token });
});

app.publish(“/translate”, async (req, res) => {
const { textual content, target_lang } = req.physique;
const translation = await translator.translateText(textual content, “en”, target_lang);
res.json({ translation });
});

app.pay attention(port, () => {
console.log(`Listening on port ${port}`);
});

Frontend Growth

The frontend consists of an HTML web page with textual content areas for displaying the transcription and translation, and a button to start out and cease recording. The AssemblyAI SDK and RecordRTC library are utilized for real-time audio recording and transcription.

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″ />
<meta identify=”viewport” content material=”width=device-width, initial-scale=1.0″ />
<title>Voice Recorder with Transcription</title>
<script src=”https://cdn.tailwindcss.com”></script>
</head>
<physique>
<div class=”min-h-screen flex flex-col items-center justify-center bg-gray-100 p-4″>
<div class=”w-full max-w-6xl bg-white shadow-md rounded-lg p-4 flex flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-4″>
<div class=”flex-1″>
<label for=”transcript” class=”block text-sm font-medium text-gray-700″>Transcript</label>
<textarea id=”transcript” rows=”20″ class=”mt-1 block w-full p-2 border border-gray-300 rounded-md shadow-sm”></textarea>
</div>
<div class=”flex-1″>
<label for=”translation” class=”block text-sm font-medium text-gray-700″>Translation</label>
<choose id=”translation-language” class=”mt-1 block w-full p-2 border border-gray-300 rounded-md shadow-sm”>
<choice worth=”es”>Spanish</choice>
<choice worth=”fr”>French</choice>
<choice worth=”de”>German</choice>
<choice worth=”zh”>Chinese language</choice>
</choose>
<textarea id=”translation” rows=”18″ class=”mt-1 block w-full p-2 border border-gray-300 rounded-md shadow-sm”></textarea>
</div>
</div>
<button id=”record-button” class=”mt-4 px-6 py-2 bg-blue-500 text-white rounded-md shadow”>Report</button>
</div>
<script src=”https://www.unpkg.com/assemblyai@newest/dist/assemblyai.umd.min.js”></script>
<script src=”https://www.WebRTC-Experiment.com/RecordRTC.js”></script>
<script src=”major.js”></script>
</physique>
</html>

Actual-Time Transcription and Translation

The primary.js file handles the audio recording, transcription, and translation. The AssemblyAI real-time transcription service processes the audio, and the DeepL API interprets the ultimate transcriptions into the chosen language.

const recordBtn = doc.getElementById(“record-button”);
const transcript = doc.getElementById(“transcript”);
const translationLanguage = doc.getElementById(“translation-language”);
const translation = doc.getElementById(“translation”);

let isRecording = false;
let recorder;
let rt;

const run = async () => {
if (isRecording) {
if (rt) {
await rt.shut(false);
rt = null;
}
if (recorder) {
recorder.stopRecording();
recorder = null;
}
recordBtn.innerText = “Report”;
transcript.innerText = “”;
translation.innerText = “”;
} else {
recordBtn.innerText = “Loading…”;
const response = await fetch(“/token”);
const information = await response.json();
rt = new assemblyai.RealtimeService({ token: information.token });
const texts = {};
let translatedText = “”;
rt.on(“transcript”, async (message) => {
let msg = “”;
texts[message.audio_start] = message.textual content;
const keys = Object.keys(texts);
keys.type((a, b) => a – b);
for (const key of keys) {
if (texts[key]) {
msg += ` ${texts[key]}`;
}
}
transcript.innerText = msg;
if (message.message_type === “FinalTranscript”) {
const response = await fetch(“/translate”, {
technique: “POST”,
headers: {
“Content material-Kind”: “utility/json”,
},
physique: JSON.stringify({
textual content: message.textual content,
target_lang: translationLanguage.worth,
}),
});
const information = await response.json();
translatedText += ` ${information.translation.textual content}`;
translation.innerText = translatedText;
}
});
rt.on(“error”, async (error) => {
console.error(error);
await rt.shut();
});
rt.on(“shut”, (occasion) => {
console.log(occasion);
rt = null;
});
await rt.join();
navigator.mediaDevices
.getUserMedia({ audio: true })
.then((stream) => {
recorder = new RecordRTC(stream, {
sort: “audio”,
mimeType: “audio/webm;codecs=pcm”,
recorderType: StereoAudioRecorder,
timeSlice: 250,
desiredSampRate: 16000,
numberOfAudioChannels: 1,
bufferSize: 16384,
audioBitsPerSecond: 128000,
ondataavailable: async (blob) => {
if (rt) {
rt.sendAudio(await blob.arrayBuffer());
}
},
});
recorder.startRecording();
recordBtn.innerText = “Cease Recording”;
})
.catch((err) => console.error(err));
}
isRecording = !isRecording;
};
recordBtn.addEventListener(“click on”, () => {
run();
});

Conclusion

This tutorial demonstrates how one can construct a real-time language translation service utilizing AssemblyAI and DeepL in JavaScript. Such a software can considerably improve communication and accessibility for customers in several linguistic contexts. For extra detailed directions, go to the unique AssemblyAI tutorial.

Picture supply: Shutterstock



Source link

Tags: AssemblyAIBuildingDeepLJavaScriptLanguageRealTimeTranslation
Previous Post

Exploring New Revenue Streams with Blockchain Payment Use Cases

Next Post

The Wildest Ways ‘Hamster Kombat’ Players Are Boosting Their Telegram Tapping

Related Posts

The Graph Backs x402 and ERC-8004 Standards for AI Agent Economy
Blockchain

The Graph Backs x402 and ERC-8004 Standards for AI Agent Economy

February 3, 2026
OnchainDB Builds Pay-Per-Query Database on Celestia’s 1Tb/s Infrastructure
Blockchain

OnchainDB Builds Pay-Per-Query Database on Celestia’s 1Tb/s Infrastructure

February 3, 2026
SHIB Price Prediction: Targets $0.0000085 by Month-End Amid Mixed Technical Signals
Blockchain

SHIB Price Prediction: Targets $0.0000085 by Month-End Amid Mixed Technical Signals

February 3, 2026
Binance Dual Investment Challenge Offers 8,888 USDC in February Rewards
Blockchain

Binance Dual Investment Challenge Offers 8,888 USDC in February Rewards

February 3, 2026
Harvey AI Scales Legal Knowledge 10x With Autonomous Agent Pipeline
Blockchain

Harvey AI Scales Legal Knowledge 10x With Autonomous Agent Pipeline

February 2, 2026
Together AI Opens Evaluations to OpenAI, Anthropic, Google Models
Blockchain

Together AI Opens Evaluations to OpenAI, Anthropic, Google Models

February 3, 2026
Next Post
The Wildest Ways ‘Hamster Kombat’ Players Are Boosting Their Telegram Tapping

The Wildest Ways 'Hamster Kombat' Players Are Boosting Their Telegram Tapping

LandWolf Price Plunges 86% Amid Rug Pull Worries As Experts Say This New Base ICO Is One Of The Best Crypto Presales To Buy Now

LandWolf Price Plunges 86% Amid Rug Pull Worries As Experts Say This New Base ICO Is One Of The Best Crypto Presales To Buy Now

Web3 Marketing Strategist Says It’s a ‘Mistake’ to Frame Blockchain and AI as Competing Technologies

Web3 Marketing Strategist Says It’s a ‘Mistake’ to Frame Blockchain and AI as Competing Technologies

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Twitter Instagram LinkedIn Telegram RSS
The Crypto HODL

Find the latest Bitcoin, Ethereum, blockchain, crypto, Business, Fintech News, interviews, and price analysis at The Crypto HODL

CATEGORIES

  • Altcoin
  • Analysis
  • Bitcoin
  • Blockchain
  • Crypto Exchanges
  • Crypto Mining
  • Crypto Updates
  • DeFi
  • Ethereum
  • Metaverse
  • NFT
  • Regulations
  • Scam Alert
  • Uncategorized
  • Videos
  • Web3

SITE MAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 The Crypto HODL.
The Crypto HODL is not responsible for the content of external sites.

No Result
View All Result
  • Home
  • Bitcoin
  • Crypto Updates
    • Altcoin
    • Ethereum
    • Crypto Updates
    • Crypto Mining
    • Crypto Exchanges
  • Blockchain
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Regulations
  • Scam Alert
  • Analysis
  • Videos
Crypto Marketcap

Copyright © 2023 The Crypto HODL.
The Crypto HODL is not responsible for the content of external sites.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In