Skip to content

Commit

Permalink
feat: Refactor file handling in main script
Browse files Browse the repository at this point in the history
- Implement a new function `read_transcription` in main.py for reading transcription text from an output file
- Utilize the `read_transcription` function for retrieving the transcription text instead of direct file reading
- Enhance error handling by printing error message and raising the exception during file processing in main.py
  • Loading branch information
johnnyhuy committed Apr 5, 2024
1 parent 11c9a90 commit eafe976
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions transcribe_me/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ def append_to_shell_profile(line):

print(f"API key added to {profile_file}")

def read_transcription(output_file: str) -> str:
"""
Read the transcription from the specified output file.
Args:
output_file (str): The path to the output file.
Returns:
str: The transcription text.
"""
with open(output_file, "r", encoding="utf-8") as file:
transcription = file.read()
return transcription

def main():
parser = argparse.ArgumentParser(description="Transcribe audio files and generate summaries.")
Expand Down Expand Up @@ -274,15 +287,14 @@ def main():
print(f"Transcribing audio file: {file_path}")
transcribe_audio(file_path, output_file)
files_transcribed = True
else:
with open(output_file, "r", encoding="utf-8") as file:
transcription = file.read()
continue

with open(DEFAULT_CONFIG_FILE, "r") as f:
config = yaml.safe_load(f)

openai_models = config["openai"]["models"]
anthropic_models = config["anthropic"]["models"]
transcription = read_transcription(output_file)

# Save summaries in markdown files
for model_config in openai_models:
Expand Down Expand Up @@ -332,6 +344,7 @@ def main():
file.write(anthropic_summary)
except Exception as e:
print(f"An error occurred while processing {file_path}: {e}")
raise e
finally:
# Delete the _part* MP3 files
for file in glob(f"{file_path.partition('.')[0]}_part*.mp3"):
Expand Down

0 comments on commit eafe976

Please sign in to comment.