ahmadmac commited on
Commit
f59e0ec
·
verified ·
1 Parent(s): b1cffd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -23
app.py CHANGED
@@ -50,29 +50,26 @@
50
 
51
 
52
  import streamlit as st
53
- import sounddevice as sd
54
- import numpy as np
55
- import io
56
- import wavio
57
  from fpdf import FPDF
58
 
59
- # Function to handle voice input using sounddevice
60
  def voice_input():
61
- st.write("Listening...")
62
- fs = 44100 # Sample rate
63
- duration = 5 # Duration in seconds
64
-
65
- # Record audio
66
- audio_data = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16')
67
- sd.wait() # Wait until recording is finished
68
-
69
- # Save to a WAV file
70
- wav_buffer = io.BytesIO()
71
- wavio.write(wav_buffer, audio_data, fs, sampwidth=2)
72
- wav_buffer.seek(0)
73
-
74
- # Convert audio to text (placeholder, you need to use a library/service for actual transcription)
75
- return "Symptoms recognized: Placeholder text from audio"
76
 
77
  # Function to simulate disease prediction
78
  def predict_disease(symptoms):
@@ -87,7 +84,7 @@ def save_to_pdf(content):
87
  pdf.cell(200, 10, txt="Medical Assistance Results", ln=True, align='C')
88
  pdf.ln(10)
89
  pdf.multi_cell(0, 10, content)
90
- pdf_output = io.BytesIO()
91
  pdf.output(pdf_output)
92
  pdf_output.seek(0)
93
  return pdf_output
@@ -109,7 +106,6 @@ save_as_pdf = st.checkbox("Save result as PDF")
109
  if st.button("Submit"):
110
  if use_voice_input:
111
  symptoms = voice_input() # Get symptoms via voice input
112
- st.write(f"Symptoms recognized: {symptoms}")
113
  else:
114
  symptoms = symptoms_input # Use keyboard input
115
 
@@ -126,4 +122,3 @@ if st.button("Submit"):
126
  file_name="medical_assistance.pdf",
127
  mime="application/pdf"
128
  )
129
-
 
50
 
51
 
52
  import streamlit as st
53
+ import speech_recognition as sr
54
+ from io import BytesIO
 
 
55
  from fpdf import FPDF
56
 
57
+ # Function to handle voice input using speech_recognition
58
  def voice_input():
59
+ recognizer = sr.Recognizer()
60
+ with sr.Microphone() as source:
61
+ st.write("Listening...")
62
+ audio = recognizer.listen(source)
63
+ try:
64
+ text = recognizer.recognize_google(audio)
65
+ st.write(f"Recognized: {text}")
66
+ return text
67
+ except sr.UnknownValueError:
68
+ st.write("Google Speech Recognition could not understand the audio")
69
+ return ""
70
+ except sr.RequestError as e:
71
+ st.write(f"Could not request results from Google Speech Recognition service; {e}")
72
+ return ""
 
73
 
74
  # Function to simulate disease prediction
75
  def predict_disease(symptoms):
 
84
  pdf.cell(200, 10, txt="Medical Assistance Results", ln=True, align='C')
85
  pdf.ln(10)
86
  pdf.multi_cell(0, 10, content)
87
+ pdf_output = BytesIO()
88
  pdf.output(pdf_output)
89
  pdf_output.seek(0)
90
  return pdf_output
 
106
  if st.button("Submit"):
107
  if use_voice_input:
108
  symptoms = voice_input() # Get symptoms via voice input
 
109
  else:
110
  symptoms = symptoms_input # Use keyboard input
111
 
 
122
  file_name="medical_assistance.pdf",
123
  mime="application/pdf"
124
  )