HenestrosaDev / audiotext

A desktop application that transcribes audio from files, microphone input or YouTube videos with the option to translate the content and create subtitles.
Other
112 stars 10 forks source link

Auto Save Transcript When Complete #17

Closed 1angstrom closed 1 month ago

1angstrom commented 1 month ago

Overview

I propose a checkbox that saves a srt, vrt, or txt file automatically in the directory (assuming it isn't overwriting an existing file with the same name) as soon as the transcription of a file is complete.

Motivation

The problem that this solves is not necessarily for one-off files. But if in the future a feature is added that allows transcription of multiple files at once this would be extremely useful.

Proposal

The way to implement this would likely be an additional checkbox on the GUI that asks the user if they want to autosave the transcript and in what formats they want autosaved. Before saving there should be a check to see if there is an existing file with the same name. An additional checkbox could be added to either always overwrite, with the default being to not overwrite any files with the same name.

Alternatives Considered

None. I'm open to hearing what others think of though

Additional Context

As stated above, I think that the greatest advantage of this feature would be if additional functionality gets added in the future that transcribes multiple files at once.

Next Steps

I am unfamiliar with how to go about executing the next steps myself but after messing around with chat GPT this is what it thinks the best next steps are:

Technical Implementation Details

  1. UI Changes:

Add Checkboxes to the GUI: Create a new checkbox labeled "Autosave Transcript" in the transcription settings panel. Add additional checkboxes or a dropdown menu for selecting the file formats (SRT, VRT, TXT) for autosaving. Add a checkbox labeled "Overwrite Existing Files" with a default setting of not overwriting existing files.

Pseudocode for GUI elements

autosave_checkbox = CheckBox("Autosave Transcript") format_checkbox_srt = CheckBox("Save as SRT") format_checkbox_vrt = CheckBox("Save as VRT") format_checkbox_txt = CheckBox("Save as TXT") overwrite_checkbox = CheckBox("Overwrite Existing Files", default=False)

settings_panel.add(autosave_checkbox) settings_panel.add(format_checkbox_srt) settings_panel.add(format_checkbox_vrt) settings_panel.add(format_checkbox_txt) settings_panel.add(overwrite_checkbox)

  1. File Saving Logic:

Determine File Path and Name: Construct the file path based on the directory where the original file is located and append the appropriate file extension for the selected formats.

Pseudocode

def get_file_path(original_file_path, extension): directory = os.path.dirname(original_file_path) base_name = os.path.splitext(os.path.basename(original_file_path))[0] return os.path.join(directory, f"{base_name}.{extension}") Check for Existing Files: Before saving, check if a file with the same name already exists in the directory. If the "Overwrite Existing Files" checkbox is not selected and a file exists, generate a new file name or skip saving. python

Pseudocode

def check_and_save_file(file_path, content, overwrite): if os.path.exists(file_path): if overwrite: save_file(file_path, content) else: new_file_path = generate_unique_filename(file_path) save_file(new_file_path, content) else: save_file(file_path, content)

def generate_unique_filename(file_path): base, extension = os.path.splitext(file_path) counter = 1 new_filepath = f"{base}{counter}{extension}" while os.path.exists(new_file_path): counter += 1 new_filepath = f"{base}{counter}{extension}" return new_file_path

3. Saving the Transcription:

Function to Save Files: Implement the logic to save the transcription content into the specified file formats.

Pseudocode

def save_file(file_path, content): with open(file_path, 'w') as file: file.write(content)

def autosave_transcription(original_file_path, transcript, formats, overwrite): for fmt in formats: file_path = get_file_path(original_file_path, fmt) check_and_save_file(file_path, transcript, overwrite)

  1. Integration with Transcription Completion:

Hook into the Transcription Process: Modify the transcription process to include a call to the autosave function when the transcription is complete.

Pseudocode

def on_transcription_complete(original_file_path, transcript): if autosave_checkbox.is_checked(): selected_formats = [] if format_checkbox_srt.is_checked(): selected_formats.append('srt') if format_checkbox_vrt.is_checked(): selected_formats.append('vrt') if format_checkbox_txt.is_checked(): selected_formats.append('txt')

    overwrite = overwrite_checkbox.is_checked()
    autosave_transcription(original_file_path, transcript, selected_formats, overwrite)
  1. Testing and Validation:

Unit Tests: Write unit tests to validate the file saving logic, including scenarios with existing files and different user preferences for overwriting.

Pseudocode

def test_generate_unique_filename():

Add tests to validate unique file name generation

def test_check_and_save_file():

Add tests to validate file saving logic with and without overwriting

def test_autosave_transcription():

Add tests to validate the autosave functionality for different formats

  1. Documentation:

Update User Guide: Include instructions and screenshots in the user guide to explain how to use the new autosave feature and configure the settings.

HenestrosaDev commented 1 month ago

Thank you for the thorough description of the feature! I can definitely see it being implemented into the project, so I'll add it to the roadmap and work on it whenever I have the time. However, I I'm not going to include the checkbox to let the user choose the extension of the file. What I'll do instead is save the .txt file by default if the checkbox is checked, and then also save the subtitle files automatically if the Generate subtitles checkbox is checked. I think it's more convenient this way.

As for transcribing multiple files, I'm not quite sure about how to include it in the program, as I originally planned to transcribe one file at a time. I'll have to figure out how to include the option according to the current structure of the project.

1angstrom commented 1 month ago

Awesome! Thanks for reading/ considering my input and thank you for making a cool app :)

TienNM commented 1 month ago

Hi ! It's truely awesome app, im surprising to how accurate it transcript. I tried the subtitle feature which i understand that it will provide text with the timestamp. But when saving transcription it does nothing. No .srt file & the .txt file is empty. Maybe it has some error on my window. I used window 10 64 bit. Anyway thanks for your nice app.

HenestrosaDev commented 1 month ago

Hi ! It's truely awesome app, im surprising to how accurate it transcript. I tried the subtitle feature which i understand that it will provide text with the timestamp. But when saving transcription it does nothing. No .srt file & the .txt file is empty. Maybe it has some error on my window. I used window 10 64 bit. Anyway thanks for your nice app.

Hi!

Thank you for your feedback! I'll take a look at it as soon as I can to see what's wrong.

TienNM commented 1 month ago

Thank you ! Much appreciated.

pordeciralgo commented 1 month ago

Hi ! It's truely awesome app, im surprising to how accurate it transcript. I tried the subtitle feature which i understand that it will provide text with the timestamp. But when saving transcription it does nothing. No .srt file & the .txt file is empty. Maybe it has some error on my window. I used window 10 64 bit. Anyway thanks for your nice app.

Same issue here. No .srt and empty .txt file. Also Windows 10 x64 with Audiotext latest.

Awesome app!

HenestrosaDev commented 1 month ago

@pordeciralgo @TienNM I've been testing the generation of subtitles and I haven't encountered the problem you guys are reporting. Do you always have this problem or does it only happen with certain audios?

pordeciralgo commented 1 month ago

After the problem, I've tested with two other audios and the subtitle generation has worked as expected, both .txt and .srt (and .vtt)

Then I've tried again with the first audio... and, again, empty .txt file and no .srt

Please let me know if you need more info. I can provide that particular file if you need it.

HenestrosaDev commented 1 month ago

After the problem, I've tested with two other audios and the subtitle generation has worked as expected, both .txt and .srt (and .vtt)

Then I've tried again with the first audio... and, again, empty .txt file and no .srt

Please let me know if you need more info. I can provide that particular file if you need it.

It would be nice if you could share the audio you are having problems with.

HenestrosaDev commented 1 month ago

I'm closing this issue as I've already finished adding the 'Autosave' and 'Overwrite existing files' options. Please @pordeciralgo open an issue with the audio to keep the issues separate.

HenestrosaDev commented 1 month ago

@1angstrom I've just released version 2.2.2 with this feature and the ability to transcribe an entire directory.

1angstrom commented 1 month ago

Same issue here. No .srt and empty .txt file

this happened to me also and I don't know why it would work on most files and not work on a few.

1angstrom commented 1 month ago

@1angstrom I've just released version 2.2.2 with this feature and the ability to transcribe an entire directory.

That's awesome!