Update voice_of_the_patient.py
Browse files- voice_of_the_patient.py +7 -2
voice_of_the_patient.py
CHANGED
@@ -9,6 +9,10 @@ load_dotenv()
|
|
9 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
10 |
|
11 |
def record_audio(file_path, timeout=20 ,phrase_time_limit=10):
|
|
|
|
|
|
|
|
|
12 |
|
13 |
recognizer = sr.Recognizer()
|
14 |
|
@@ -23,9 +27,10 @@ def record_audio(file_path, timeout=20 ,phrase_time_limit=10):
|
|
23 |
|
24 |
wav_data = audio_data.get_wav_data()
|
25 |
audio_segment = AudioSegment.from_wav(BytesIO(wav_data))
|
26 |
-
|
|
|
27 |
|
28 |
-
logging.info(f"Audio saved to {
|
29 |
|
30 |
except Exception as e:
|
31 |
logging.error(f"An error occurred: {str(e)}")
|
|
|
9 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
10 |
|
11 |
def record_audio(file_path, timeout=20 ,phrase_time_limit=10):
|
12 |
+
|
13 |
+
if not file_path:
|
14 |
+
logging.error("No file path provided")
|
15 |
+
return None
|
16 |
|
17 |
recognizer = sr.Recognizer()
|
18 |
|
|
|
27 |
|
28 |
wav_data = audio_data.get_wav_data()
|
29 |
audio_segment = AudioSegment.from_wav(BytesIO(wav_data))
|
30 |
+
abs_file_path = os.path.abspath(file_path)
|
31 |
+
audio_segment.export(abs_file_path, format="mp3", bitrate='128k')
|
32 |
|
33 |
+
logging.info(f"Audio saved to {abs_file_path}")
|
34 |
|
35 |
except Exception as e:
|
36 |
logging.error(f"An error occurred: {str(e)}")
|