Browse Source

update audio file name parameter

SherryLiu 4 months ago
parent
commit
1fadd4f95c
2 changed files with 32 additions and 14 deletions
  1. 1 1
      README.md
  2. 31 13
      src/main_script.py

+ 1 - 1
README.md

@@ -9,4 +9,4 @@
 `pip install -r requirements.txt`
 
 ### 執行主程式
-`python src/main_script.py`
+`python src/main_script.py <audio filename>`

+ 31 - 13
src/main_script.py

@@ -1,3 +1,4 @@
+import sys
 from dictionary_loader import load_dictionary_from_supabase
 from audio_processing import process_audio
 
@@ -6,19 +7,36 @@ def initialize():
     if not success:
         print("Warning: Dictionary loading failed. Proceeding with default dictionary.")
 
-def main():
-    initialize()  
-    sample_audio_path = "data/01.m4a"
-    with open(sample_audio_path, "rb") as audio_file:
+def process_audio_file(audio_file):
+    try:
         raw_transcript, corrected_transcript = process_audio(audio_file)
-    
-    if raw_transcript and corrected_transcript:
-        # print("Raw Transcript:")
-        # print(raw_transcript)
-        # print("\nCorrected Transcript:")
-        print(corrected_transcript)
-    else:
-        print("Audio processing failed.")
+        if raw_transcript and corrected_transcript:
+            return corrected_transcript
+        else:
+            return None
+    except Exception as e:
+        print(f"Error processing audio: {str(e)}")
+        return None
+
+def main(audio_file_path):
+    initialize()
+    try:
+        with open(audio_file_path, "rb") as audio_file:
+            result = process_audio_file(audio_file)
+        
+        if result:
+            print(result)
+        else:
+            print("Audio processing failed.")
+    except FileNotFoundError:
+        print(f"Error: The file '{audio_file_path}' was not found.")
+    except Exception as e:
+        print(f"An unexpected error occurred: {str(e)}")
 
 if __name__ == "__main__":
-    main()
+    if len(sys.argv) != 2:
+        print("Usage: python script_name.py <audio_file_path>")
+        sys.exit(1)
+    
+    audio_file_path = sys.argv[1]
+    main(audio_file_path)