Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions __mocks__/obsidian.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class Notice {
constructor(message: string) {
mockNotice(message);
}
}

export const mockNotice = jest.fn<void, [string]>();
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { createDefaultPreset } = require("ts-jest");

const tsJestTransformCfg = createDefaultPreset().transform;

/** @type {import("jest").Config} **/
module.exports = {
testEnvironment: "node",
transform: {
...tsJestTransformCfg,
},
};
13 changes: 8 additions & 5 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin } from "obsidian";
import { Timer } from "src/Timer";
import { Controls } from "src/Controls";
import { AudioHandler } from "src/AudioHandler";
import { Transcriber } from "src/Transcriber";
import { WhisperSettingsTab } from "src/WhisperSettingsTab";
import { SettingsManager, WhisperSettings } from "src/SettingsManager";
import { NativeAudioRecorder } from "src/AudioRecorder";
Expand All @@ -11,7 +11,7 @@ export default class Whisper extends Plugin {
settingsManager: SettingsManager;
timer: Timer;
recorder: NativeAudioRecorder;
audioHandler: AudioHandler;
transcriber: Transcriber;
controls: Controls | null = null;
statusBar: StatusBar;

Expand All @@ -29,7 +29,7 @@ export default class Whisper extends Plugin {
this.addSettingTab(new WhisperSettingsTab(this.app, this));

this.timer = new Timer();
this.audioHandler = new AudioHandler(this);
this.transcriber = new Transcriber(this);
this.recorder = new NativeAudioRecorder();

this.statusBar = new StatusBar(this);
Expand Down Expand Up @@ -63,7 +63,10 @@ export default class Whisper extends Plugin {
.toISOString()
.replace(/[:.]/g, "-")}.${extension}`;
// Use audioBlob to send or save the recorded audio as needed
await this.audioHandler.sendAudioData(audioBlob, fileName);
await this.transcriber.transcribeAndSaveResults(
audioBlob,
fileName
);
this.statusBar.updateStatus(RecordingStatus.Idle);
}
},
Expand Down Expand Up @@ -92,7 +95,7 @@ export default class Whisper extends Plugin {
const fileName = file.name;
const audioBlob = file.slice(0, file.size, file.type);
// Use audioBlob to send or save the uploaded audio as needed
await this.audioHandler.sendAudioData(
await this.transcriber.transcribeAndSaveResults(
audioBlob,
fileName
);
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"test": "jest",
"release": "release-it"
},
"keywords": [],
Expand All @@ -15,17 +16,20 @@
"@commitlint/cli": "^17.6.5",
"@commitlint/config-conventional": "^17.6.5",
"@release-it/conventional-changelog": "^5.1.1",
"@types/jest": "^30.0.0",
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"dotenv": "^16.3.1",
"esbuild": "^0.18.0",
"husky": "^8.0.3",
"jest": "^30.2.0",
"lint-staged": "^13.2.2",
"obsidian": "latest",
"prettier": "^2.8.8",
"release-it": "^15.11.0",
"ts-jest": "^29.4.5",
"tslib": "2.4.0",
"typescript": "4.7.4"
},
Expand Down
118 changes: 0 additions & 118 deletions src/AudioHandler.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/Controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Controls extends Modal {
const fileName = `${new Date()
.toISOString()
.replace(/[:.]/g, "-")}.${extension}`;
await this.plugin.audioHandler.sendAudioData(blob, fileName);
await this.plugin.transcriber.transcribeAndSaveResults(blob, fileName);
this.plugin.statusBar.updateStatus(RecordingStatus.Idle);
this.close();
}
Expand Down
Loading