Created
March 28, 2024 14:19
-
-
Save jcollingj/47ee62f24a3fda1fb39a3b004c5eabdf to your computer and use it in GitHub Desktop.
Get your stats out of Superwhisper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { readdirSync, readFileSync } from "fs"; | |
import { join } from "path"; | |
function listContentsAndAnalyzeDurations(directoryPath: string) { | |
const filesAndFolders = readdirSync(directoryPath, { withFileTypes: true }); | |
let totalRecordings = 0; | |
let durations_milliseconds: number[] = []; | |
let totalCharacters = 0; | |
let totalWords = 0; | |
filesAndFolders.forEach((dirent) => { | |
if (dirent.isDirectory()) { | |
const subPath = join(directoryPath, dirent.name); | |
const subContents = readdirSync(subPath, { withFileTypes: true }); | |
subContents.forEach((subDirent) => { | |
if (subDirent.isFile() && subDirent.name === "meta.json") { | |
totalRecordings++; | |
const metaPath = join(subPath, subDirent.name); | |
const metaData = JSON.parse(readFileSync(metaPath, { encoding: "utf-8" })); | |
durations_milliseconds.push(metaData.duration); // Keep duration in milliseconds | |
const resultText = metaData.result; | |
totalCharacters += resultText.length; | |
totalWords += resultText.split(/\s+/).length; | |
} | |
}); | |
} | |
}); | |
const totalDurationMilliseconds = durations_milliseconds.reduce((acc, duration) => acc + duration, 0); | |
const maxDurationMilliseconds = Math.max(...durations_milliseconds); | |
const avgDurationMilliseconds = totalDurationMilliseconds / durations_milliseconds.length; | |
// Convert milliseconds to minutes and seconds for display | |
const totalDurationMinutes = Math.floor(totalDurationMilliseconds / 60000); | |
const totalDurationSeconds = ((totalDurationMilliseconds % 60000) / 1000).toFixed(0); | |
const maxDurationMinutes = Math.floor(maxDurationMilliseconds / 60000); | |
const maxDurationSeconds = ((maxDurationMilliseconds % 60000) / 1000).toFixed(0); | |
const avgDurationMinutes = Math.floor(avgDurationMilliseconds / 60000); | |
const avgDurationSeconds = ((avgDurationMilliseconds % 60000) / 1000).toFixed(0); | |
console.log(`Total recordings: ${totalRecordings}`); | |
console.log( | |
`Total duration from all recordings: ${totalDurationMinutes} minutes and ${totalDurationSeconds} seconds` | |
); | |
console.log(`Max recording duration: ${maxDurationMinutes} minutes and ${maxDurationSeconds} seconds`); | |
console.log(`Average recording duration: ${avgDurationMinutes} minutes and ${avgDurationSeconds} seconds`); | |
console.log(`Total characters in results: ${totalCharacters.toLocaleString()}`); | |
console.log(`Total words in results: ${totalWords.toLocaleString()}`); | |
} | |
// Example usage | |
const user = ""; | |
const recordingsPath = `/Users/${user}/Documents/superwhisper/recordings`; | |
listContentsAndAnalyzeDurations(recordingsPath); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment