adityajat/SaarvamAI_botPublic · Bot Template

ProfileTelegram

AISarvam AI is a multi‑purpose Telegram bot that lets users ask questions, get explanations, convert text to speech, and translate messages using the Sarvam AI API. It also offers group administration commands such as warn, mute, ban, pin, delete, and announcements, and can clear personal or group AI memory. The bot uses the TeleBotHost TBL framework with Bot, Api, db, and HTTP calls, and provides inline keyboards for language and voice selection.

Ai Assistantaivoicetranslatemoderationadminsarvam
34 commands4 envUpdated 15d agoCreated Sep 14, 2026
Back to folder

commands/_dub.js

javascript · 69 lines

Raw
1/**#command2name: /dub3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12const API_KEY = "YOUR_API_KEY";13const BASE_URL = "https://studio.sarvam.ai/api/dubbing";14 15// Step 1: Create dubbing project16const createRes = await fetch(`${BASE_URL}/jobs`, {17  method: "POST",18  headers: {19    "api-subscription-key": API_KEY,20    "Content-Type": "application/json",21  },22  body: JSON.stringify({23    src_lang: "en-IN",24    target_langs: ["hi-IN"],25    num_speakers: 2,26    voice_cloning: true,27    register: "auto",28    editor_flow: false,29  }),30});31const { data } = await createRes.json();32const { job_id, upload_url } = data;33console.log("Job created:", job_id);34 35// Step 2: Upload video36const videoFile = document.querySelector("input[type=file]").files[0];37await fetch(upload_url, {38  method: "PUT",39  headers: { "x-ms-blob-type": "BlockBlob", "Content-Type": "video/mp4" },40  body: videoFile,41});42console.log("Video uploaded");43 44// Step 3: Start processing45await fetch(`${BASE_URL}/jobs/${job_id}/start`, {46  method: "POST",47  headers: { "api-subscription-key": API_KEY },48});49console.log("Processing started");50 51// Step 4: Poll until completed52const poll = async () => {53  while (true) {54    const res = await fetch(`${BASE_URL}/jobs/${job_id}/live-status`, {55      headers: { "api-subscription-key": API_KEY },56    });57    const { data: status } = await res.json();58    console.log(`Progress: ${status.progress}% — ${status.current_step_label}`);59    if (status.status === "completed") {60      console.log("Done! Download:", status.export.dubbed_video_url);61      return status;62    }63    if (status.status === "failed") {64      throw new Error(status.error_message);65    }66    await new Promise((r) => setTimeout(r, 10000));67  }68};69await poll();