main_script.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import sys
  2. from api.openai_scripts_tai_gi.dictionary_loader import load_word_database_dictionary_from_supabase
  3. from api.openai_scripts_tai_gi.audio_processing import process_audio
  4. def initialize():
  5. word_database_success = load_word_database_dictionary_from_supabase()
  6. if not word_database_success:
  7. print("Warning: Word Database Dictionary loading failed. Proceeding with default dictionary.")
  8. def process_audio_file(audio_file):
  9. try:
  10. result = process_audio(audio_file)
  11. if isinstance(result, tuple) and len(result) == 2:
  12. return result
  13. else:
  14. print("Unexpected result from process_audio")
  15. return None, None
  16. except Exception as e:
  17. print(f"Error processing audio: {str(e)}")
  18. return None, None
  19. # 加入檢查user是否詢問特定問題
  20. def main(audio_file):
  21. initialize()
  22. try:
  23. raw_transcript, corrected_transcript = process_audio_file(audio_file)
  24. return raw_transcript, corrected_transcript
  25. except FileNotFoundError:
  26. print(f"Error: The file was not found.")
  27. return None, None
  28. except Exception as e:
  29. print(f"An unexpected error occurred: {str(e)}")
  30. import traceback
  31. traceback.print_exc()
  32. return None, None
  33. if __name__ == "__main__":
  34. if len(sys.argv) != 2:
  35. print("Usage: python script_name.py <audio_file_path>")
  36. sys.exit(1)
  37. audio_file_path = sys.argv[1]
  38. main(audio_file_path)