Skip to content

Commit

Permalink
Added keep audio file + player settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mossy426 committed Aug 21, 2024
1 parent 70ba978 commit 5319c4f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
16 changes: 12 additions & 4 deletions SmartMemosAudioRecordModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class SmartMemosAudioRecordModal extends Modal {
private chunks: BlobPart[] = [];
private resolve: (value: Blob | PromiseLike<Blob>) => void;
private reject: (reason?: any) => void;
private handleAudioRecording: (audioFile: Blob | null, transcribe: boolean, keepAudio: boolean) => void;
private handleAudioRecording: (audioFile: Blob | null, transcribe: boolean, keepAudio: boolean, includeAudioFileLink: boolean) => void;
private isRecording: boolean = false;
private timer: HTMLElement;
private intervalId: number | null = null;
Expand All @@ -14,9 +14,10 @@ export class SmartMemosAudioRecordModal extends Modal {
private redDot: HTMLElement;
private isResetting: boolean = false; // Flag to track reset state
private keepAudioCheckbox: HTMLElement; // Add a property for the checkbox
private includeAudioFileLinkCheckbox: HTMLElement; // Add a property for the checkbox
private settings: any;

constructor(app: any, handleAudioRecording: (audioFile: Blob | null, transcribe: boolean, keepAudio: boolean) => void, settings: any) {
constructor(app: any, handleAudioRecording: (audioFile: Blob | null, transcribe: boolean, keepAudio: boolean, includeAudioFileLink: boolean) => void, settings: any) {
super(app);
this.handleAudioRecording = handleAudioRecording;
this.settings = settings; // Initialize settings
Expand Down Expand Up @@ -56,7 +57,7 @@ export class SmartMemosAudioRecordModal extends Modal {

stopButton.addEventListener('click', async () => {
const audioFile = await this.stopRecording();
this.handleAudioRecording(audioFile, false, (this.keepAudioCheckbox as HTMLInputElement).checked);
this.handleAudioRecording(audioFile, false, (this.keepAudioCheckbox as HTMLInputElement).checked, (this.includeAudioFileLinkCheckbox as HTMLInputElement).checked);
});

playPauseButton.addEventListener('click', () => {
Expand All @@ -80,7 +81,7 @@ export class SmartMemosAudioRecordModal extends Modal {

transcribeButton.addEventListener('click', async () => {
const audioFile = await this.stopRecording();
this.handleAudioRecording(audioFile, true, (this.keepAudioCheckbox as HTMLInputElement).checked);
this.handleAudioRecording(audioFile, true, (this.keepAudioCheckbox as HTMLInputElement).checked, (this.includeAudioFileLinkCheckbox as HTMLInputElement).checked);
});

setIcon(transcribeButton, 'file-text'); // Initially set to bulb
Expand Down Expand Up @@ -113,6 +114,13 @@ export class SmartMemosAudioRecordModal extends Modal {
const keepAudioLabel = keepAudioContainer.createEl('label', { text: 'Keep Audio File', cls: 'smart-memo-keep-audio-label' });
keepAudioLabel.htmlFor = this.keepAudioCheckbox.id;

// Add the checkbox for including audio file link
const includeAudioFileLinkContainer = contentEl.createDiv({ cls: 'smart-memo-include-audio-file-link-container' });
this.includeAudioFileLinkCheckbox = includeAudioFileLinkContainer.createEl('input', { type: 'checkbox', cls: 'smart-memo-include-audio-file-link-checkbox' });
(this.includeAudioFileLinkCheckbox as HTMLInputElement).checked = this.settings.includeAudioFileLink; // Set checked based on settings
const includeAudioFileLinkLabel = includeAudioFileLinkContainer.createEl('label', { text: 'Include Audio File Player', cls: 'smart-memo-include-audio-file-link-label' });
includeAudioFileLinkLabel.htmlFor = this.includeAudioFileLinkCheckbox.id;

// Start recording immediately upon opening the modal
this.startRecording();
this.isRecording = true;
Expand Down
36 changes: 31 additions & 5 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface AudioPluginSettings {
includeTranscript: boolean;
recordingFilePath: string;
keepAudio: boolean;
includeAudioFileLink : boolean;
}

let DEFAULT_SETTINGS: AudioPluginSettings = {
Expand All @@ -20,7 +21,8 @@ let DEFAULT_SETTINGS: AudioPluginSettings = {
prompt: 'You are an expert note-making AI for obsidian who specializes in the Linking Your Thinking (LYK) strategy. The following is a transcription of recording of someone talking aloud or people in a conversation. There may be a lot of random things said given fluidity of conversation or thought process and the microphone\'s ability to pick up all audio. Give me detailed notes in markdown language on what was said in the most easy-to-understand, detailed, and conceptual format. Include any helpful information that can conceptualize the notes further or enhance the ideas, and then summarize what was said. Do not mention \"the speaker\" anywhere in your response. The notes your write should be written as if I were writting them. Finally, ensure to end with code for a mermaid chart that shows an enlightening concept map combining both the transcription and the information you added to it. The following is the transcribed audio:\n\n',
includeTranscript: true,
recordingFilePath: '',
keepAudio: true
keepAudio: true,
includeAudioFileLink: false
}

const MODELS: string[] = [
Expand Down Expand Up @@ -124,7 +126,7 @@ export default class SmartMemosPlugin extends Plugin {
}

// Add a new method to handle the audio recording and processing
async handleAudioRecording(audioFile: Blob, transcribe: boolean, keepAudio: boolean) {
async handleAudioRecording(audioFile: Blob, transcribe: boolean, keepAudio: boolean, includeAudioFileLink: boolean) {
try {
console.log('Handling audio recording:', audioFile);

Expand All @@ -140,11 +142,11 @@ export default class SmartMemosPlugin extends Plugin {
const file = await saveFile(this.app, this.audioFile, fileName, this.settings.recordingFilePath);

this.settings.keepAudio = keepAudio;

this.settings.includeAudioFileLink = includeAudioFileLink;
this.saveSettings();

// Only save the audio file if keepAudio is true
if (keepAudio) {
// Only save the audio file if use wants to include it and they are keeping the audio
if (includeAudioFileLink && keepAudio) {
// Insert a link to the audio file in the current note
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView) {
Expand Down Expand Up @@ -191,6 +193,10 @@ export default class SmartMemosPlugin extends Plugin {
const prompt = this.settings.prompt + result;
new Notice('Transcript generated...');
this.generateText(prompt, editor , editor.getCursor('to').line);
//if keepAudio is false and delete the audio file if so
if (!this.settings.keepAudio) {
this.app.vault.delete(audioFile); // Delete the audio file
}
}).catch(error => {
console.warn(error.message);
new Notice(error.message);
Expand Down Expand Up @@ -495,6 +501,26 @@ class SmartMemosSettingTab extends PluginSettingTab {
this.plugin.settings.recordingFilePath = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Save Audio File')
.setDesc('Toggle this setting if you want to save/remove the audio file after it has been transcribed.')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.keepAudio)
.onChange(async (value) => {
this.plugin.settings.keepAudio = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Include Audio Player')
.setDesc('Toggle this setting if you want the audio file player to be displayed along with the transcription.')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.includeAudioFileLink)
.onChange(async (value) => {
this.plugin.settings.includeAudioFileLink = value;
await this.plugin.saveSettings();
}));

}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "smart-memos",
"name": "Smart Memos",
"version": "1.1.6",
"version": "1.1.7",
"minAppVersion": "0.15.0",
"description": "Create personalized and intelligent analysis, summaries, and more for audio recordings that can be imported or spoken directly into a note",
"author": "Evan Moscoso",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smart-memos",
"version": "1.1.6",
"version": "1.1.7",
"description": "Create personalized and intelligent analysis, summaries, and more for audio recordings that can be imported or spoken directly into a note",
"main": "main.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ body .modal-container .modal.smart-memo-recording {
animation-play-state: paused;
}

.smart-memo-keep-audio-container {
margin-bottom: -20px;
}

/* Add this CSS to your existing stylesheet */
body .modal-container .modal .smart-memo-modal-button:focus,
body .modal-container .modal .smart-memo-modal-button:focus-visible {
Expand Down

0 comments on commit 5319c4f

Please sign in to comment.