# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/04_transribe.ipynb.

# %% auto 0
__all__ = ['transcribe_audio', 'transcribing_process']

# %% ../nbs/04_transribe.ipynb 1
import os
import whisper
import time
from .sounds import *
from . import notion

# %% ../nbs/04_transribe.ipynb 2
# Function to transcribe audio
def transcribe_audio(filename):
    # Load the Whisper model
    model = whisper.load_model("small.en")
    result = model.transcribe(filename)
    return result["text"]

def transcribing_process():
    while True:
        try:
            time.sleep(5)
            print("Checking for completed recordings...")
            for file in os.listdir("completed_recordings"):
                if file.endswith(".wav"):
                    audio_file_path = os.path.join("completed_recordings", file)
                    print(f"Transcribing {audio_file_path}")
                    transcription = transcribe_audio(audio_file_path)
                    print("Transcription:", transcription)
                    notion.append_to_notion(transcription)
                    play_success_sound()
                    os.remove(audio_file_path)
                    print(f"Transcription uploaded to Notion and {audio_file_path} deleted.")
        except Exception as e:
            print(e)
            print(f"Error while transcribing and uploading audio. Trying again in 5 seconds...")
