Skip to content

Commit

Permalink
refactor(progressBar): Ensures that the progress bar starts running w…
Browse files Browse the repository at this point in the history
…hen it is able to recognize the file size and move it to a separate function
  • Loading branch information
51L3N7-X committed Apr 2, 2024
1 parent eb07c05 commit f099323
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
31 changes: 2 additions & 29 deletions src/modules/cachedFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import {
} from "fs";
import { resolve } from "path";
import axios from "axios";
import cliProgress from "cli-progress";
import colors from "ansi-colors";
import formatBytes from "../utils/formatBytes.js";
import downloadProgressBar from "../utils/axiosDownload.js";

let inited = false;
let mapPath = "";
Expand Down Expand Up @@ -100,33 +98,8 @@ export default async function cachedFetch(url, params = {}) {
return mkResponse(buffer, path);
}

const downloadProgress = new cliProgress.SingleBar({
// eslint-disable-next-line max-len
format: `Downloading Audio | ${colors.cyan("{bar}")} | {percentage}% || {loaded}/{all} MB || Speed: {speed}`,
barCompleteChar: "\u2588",
barIncompleteChar: "\u2591",
hideCursor: true,
});

let first = true;

const res = await axios.get(fullUrl, {
onDownloadProgress: (progress) => {
if (first) {
first = false;
downloadProgress.start(progress.total, progress.loaded, {
speed: `${formatBytes(progress.rate, 1)}KB/s` || "N/A",
loaded: formatBytes(progress.loaded, 2) || "??",
all: formatBytes(progress.total, 2) || "??",
});
}
if (!progress.total) first = true;
downloadProgress.update(progress.loaded, {
speed: `${formatBytes(progress.rate) || "??"}KB/S`,
loaded: formatBytes(progress.loaded) || "??",
all: formatBytes(progress.total) || "??",
});
},
onDownloadProgress: downloadProgressBar("Downloading Audio"),
responseType: "arraybuffer",
});
const buffer = Buffer.from(res.data);
Expand Down
30 changes: 30 additions & 0 deletions src/utils/axiosDownload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import cliProgress from "cli-progress";
import colors from "ansi-colors";
import formatBytes from "./formatBytes.js";

const downloadProgressBar = (text) => {
const downloadProgress = new cliProgress.SingleBar({
// eslint-disable-next-line max-len
format: `${text} | ${colors.cyan("{bar}")} | {percentage}% || {loaded}/{all} MB || Speed: {speed}`,
barCompleteChar: "\u2588",
barIncompleteChar: "\u2591",
hideCursor: true,
});

return (progress) => {
if (progress.total) {
downloadProgress.start(progress.total, progress.loaded, {
speed: `${formatBytes(progress.rate, 1)}KB/s` || "N/A",
loaded: formatBytes(progress.loaded, 2) || "??",
all: formatBytes(progress.total, 2) || "??",
});
downloadProgress.update(progress.loaded, {
speed: `${formatBytes(progress.rate) || "??"}KB/S`,
loaded: formatBytes(progress.loaded) || "??",
all: formatBytes(progress.total) || "??",
});
}
};
};

export default downloadProgressBar;
Binary file modified vid.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion whisper/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import whisper_timestamped as whisper
import json

# Load audio and model (same as your previous code)
# Load audio and model
audio = whisper.load_audio("tt.mp3")
model = whisper.load_model("large", device="cuda")
result = whisper.transcribe(model, audio, language="ar")
Expand Down

0 comments on commit f099323

Please sign in to comment.