nagasurendra commited on
Commit
fd0208c
·
verified ·
1 Parent(s): 32feee0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -1,14 +1,10 @@
1
  import speech_recognition as sr
2
- import pyttsx3
3
  import whisper
4
  from simple_salesforce import Salesforce
5
  from flask import Flask, jsonify
6
 
7
  app = Flask(__name__)
8
 
9
- # Initialize Text-to-Speech (TTS) Engine
10
- engine = pyttsx3.init()
11
-
12
  # Initialize Whisper Model
13
  model = whisper.load_model("base")
14
 
@@ -19,16 +15,15 @@ sf = Salesforce(
19
  security_token="sSSjyhInIsUohKpG8sHzty2q"
20
  )
21
 
22
- def speak(text):
23
- """Speak the given text"""
24
- engine.say(text)
25
- engine.runAndWait()
26
 
27
  def listen():
28
  """Capture live voice and return text"""
29
  recognizer = sr.Recognizer()
30
  with sr.Microphone() as source:
31
- print("Listening...")
32
  recognizer.adjust_for_ambient_noise(source) # Adjust for background noise
33
  audio = recognizer.listen(source)
34
 
@@ -71,19 +66,19 @@ def voice_login():
71
  """Main voice authentication process"""
72
 
73
  # Step 1: Ask Name
74
- speak("What is your name?")
75
  name_response = listen()
76
- print(f"User said: {name_response}")
77
  name = extract_name(name_response)
78
 
79
  if not name:
80
  return jsonify({"error": "Name not recognized"}), 400
81
 
82
- speak(f"Hello {name}, please say your phone number.")
83
 
84
  # Step 2: Ask Phone Number
85
  phone_response = listen()
86
- print(f"User said: {phone_response}")
87
  phone = extract_phone(phone_response)
88
 
89
  if not phone:
@@ -91,10 +86,10 @@ def voice_login():
91
 
92
  # Step 3: Authenticate in Salesforce
93
  if check_salesforce(name, phone):
94
- speak("Login successful! Welcome.")
95
  return jsonify({"message": "Login Successful"})
96
 
97
- speak("Login failed. Invalid credentials.")
98
  return jsonify({"error": "Invalid Credentials"}), 401
99
 
100
  if __name__ == "__main__":
 
1
  import speech_recognition as sr
 
2
  import whisper
3
  from simple_salesforce import Salesforce
4
  from flask import Flask, jsonify
5
 
6
  app = Flask(__name__)
7
 
 
 
 
8
  # Initialize Whisper Model
9
  model = whisper.load_model("base")
10
 
 
15
  security_token="sSSjyhInIsUohKpG8sHzty2q"
16
  )
17
 
18
+ def print_text(text):
19
+ """Debugging function to replace TTS output"""
20
+ print(text)
 
21
 
22
  def listen():
23
  """Capture live voice and return text"""
24
  recognizer = sr.Recognizer()
25
  with sr.Microphone() as source:
26
+ print_text("Listening...")
27
  recognizer.adjust_for_ambient_noise(source) # Adjust for background noise
28
  audio = recognizer.listen(source)
29
 
 
66
  """Main voice authentication process"""
67
 
68
  # Step 1: Ask Name
69
+ print_text("What is your name?")
70
  name_response = listen()
71
+ print_text(f"User said: {name_response}")
72
  name = extract_name(name_response)
73
 
74
  if not name:
75
  return jsonify({"error": "Name not recognized"}), 400
76
 
77
+ print_text(f"Hello {name}, please say your phone number.")
78
 
79
  # Step 2: Ask Phone Number
80
  phone_response = listen()
81
+ print_text(f"User said: {phone_response}")
82
  phone = extract_phone(phone_response)
83
 
84
  if not phone:
 
86
 
87
  # Step 3: Authenticate in Salesforce
88
  if check_salesforce(name, phone):
89
+ print_text("Login successful! Welcome.")
90
  return jsonify({"message": "Login Successful"})
91
 
92
+ print_text("Login failed. Invalid credentials.")
93
  return jsonify({"error": "Invalid Credentials"}), 401
94
 
95
  if __name__ == "__main__":