Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions voice_driven_banking/voice_banking_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from voice_simulator import VoiceCommandSimulator
from selenium_automation import VoiceBankingAutomation


class VoiceBankingTestSuite:
"""
Integrates the voice simulator with the Selenium automation to create
Expand Down Expand Up @@ -70,7 +71,10 @@ def _load_config(self, config_file):
"What are my recent transactions"
]
}
]
],
# Add support for LAMs and voice biometrics
"regional_languages_accents": ["en-US", "hi-IN", "ta-IN"],
"enable_voice_biometrics": True
}

if config_file and os.path.exists(config_file):
Expand Down Expand Up @@ -129,6 +133,18 @@ def run_tests(self):
# Clean up
self.automation.close()

def _simulate_voice_biometrics(self, command_text):
"""Simulate voice biometric authentication for secure access"""
if not self.config.get("enable_voice_biometrics", False):
return True # Skip biometric if disabled

print(f"Simulating voice biometrics for command: '{command_text}'")
# Placeholder for biometric simulation logic
# For now, assume biometric authentication passes
biometric_success = True

return biometric_success

def _test_command(self, command_name, command_text):
"""Test a single voice command and record results"""
# Simulate voice command
Expand All @@ -149,24 +165,32 @@ def _test_command(self, command_name, command_text):
print(f"Warning: Could not identify command type for '{command_name}'")
command_type = "unknown"

# Execute the command in the banking interface
result = self.automation.execute_voice_command(command_type)
# Simulate voice biometric authentication
biometric_result = self._simulate_voice_biometrics(command_text)

# Execute the command in the banking interface only if biometric passed
if biometric_result:
result = self.automation.execute_voice_command(command_type)
else:
print("Voice biometric authentication failed.")
result = False

# Record the test result
test_result = {
"command_name": command_name,
"original_command": command_text,
"recognized_command": recognized_text,
"confidence": voice_result["results"][0]["alternatives"][0]["confidence"],
"biometric_success": biometric_result,
"success": result,
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")
}

self.results["tests"].append(test_result)

# Print result
status = "PASSED" if result else "FAILED"
print(f"{status} - Original: '{command_text}', Recognized: '{recognized_text}'")
status = "PASSED" if result else "FAILED"
print(f"{status} - Original: '{command_text}', Recognized: '{recognized_text}', Biometric: {'Passed' if biometric_result else 'Failed'}")

return result

Expand Down Expand Up @@ -206,4 +230,4 @@ def main():
test_suite.run_tests()

if __name__ == "__main__":
main()
main()
49 changes: 44 additions & 5 deletions voice_driven_banking/voice_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class VoiceCommandSimulator:
text that mimics what would come from a speech-to-text system.
"""

def __init__(self, language="en-US", confidence_range=(0.85, 0.98)):
def __init__(self, language="en-US", confidence_range=(0.85, 0.98), supported_languages=None):
self.language = language
self.confidence_range = confidence_range
self.supported_languages = supported_languages or ["en-US", "hi-IN", "ta-IN"]

# Common words that might be misheard
self.sound_alikes = {
Expand Down Expand Up @@ -68,10 +69,34 @@ def generate_voice_result(self, command_text):

return result

def simulate_intent_recognition(self, command_text):
"""
Simulate NLP intent recognition by returning an intent label
based on keywords in the command text.
"""
command_text_lower = command_text.lower()
if "balance" in command_text_lower:
return "balance_inquiry"
elif "transfer" in command_text_lower or "pay" in command_text_lower:
return "fund_transfer"
elif "transaction" in command_text_lower or "history" in command_text_lower:
return "transaction_history"
else:
return "unknown_intent"

def simulate_voice_biometrics(self, command_text):
"""
Simulate voice biometric authentication.
For now, randomly succeed or fail with high probability of success.
"""
# 90% chance of successful biometric authentication
success = random.random() < 0.9
return success

def simulate_command(self, command_text):
"""
Simulate the process of speaking a command, with realistic timing
Returns the simulated recognition result
Returns the simulated recognition result including intent and biometric info
"""
# Simulate the time it takes to speak the command
speaking_time = 0.1 * len(command_text.split()) # ~100ms per word
Expand All @@ -81,8 +106,20 @@ def simulate_command(self, command_text):
processing_delay = random.uniform(0.2, 0.8) # 200-800ms
time.sleep(processing_delay)

# Generate and return the result
return self.generate_voice_result(command_text)
# Generate voice recognition result
voice_result = self.generate_voice_result(command_text)

# Simulate intent recognition
intent = self.simulate_intent_recognition(command_text)

# Simulate voice biometric authentication
biometric_success = self.simulate_voice_biometrics(command_text)

# Add intent and biometric info to the result
voice_result["intent"] = intent
voice_result["biometric_success"] = biometric_success

return voice_result

def test_simulator():
"""Test the voice command simulator with sample commands"""
Expand All @@ -101,8 +138,10 @@ def test_simulator():
result = simulator.simulate_command(command)
print(f"Simulated result: '{result['results'][0]['alternatives'][0]['transcript']}'")
print(f"Confidence: {result['results'][0]['alternatives'][0]['confidence']:.2f}")
print(f"Intent: {result['intent']}")
print(f"Biometric Success: {result['biometric_success']}")
print(f"Processing time: {result['processing_time_ms']}ms")
print("-" * 50)

if __name__ == "__main__":
test_simulator()
test_simulator()