| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- #!/usr/bin/env python3
- """
- Voice Recognition System Validation Script
- This script validates the completeness and correctness of the voice recognition
- system implementation without requiring PyTorch to be installed.
- """
- import os
- import sys
- import importlib.util
- from pathlib import Path
- from typing import List, Dict, Any
- def check_file_exists(file_path: str) -> bool:
- """Check if a file exists."""
- return Path(file_path).exists()
- def validate_module_structure() -> Dict[str, Any]:
- """Validate the module structure and file completeness."""
- base_path = Path(__file__).parent
-
- required_files = [
- '__init__.py',
- 'config.py',
- 'detector.py',
- 'audio_features.py',
- 'vad.py',
- 'model_architectures.py',
- 'model_loader.py',
- 'speaker_embeddings.py',
- 'speaker_manager.py',
- 'recognition_engine.py',
- 'optimization.py',
- 'integration.py',
- 'examples.py',
- 'README.md'
- ]
-
- results = {
- 'total_files': len(required_files),
- 'found_files': 0,
- 'missing_files': [],
- 'found_files_list': [],
- 'file_sizes': {}
- }
-
- for file_name in required_files:
- file_path = base_path / file_name
- if file_path.exists():
- results['found_files'] += 1
- results['found_files_list'].append(file_name)
- results['file_sizes'][file_name] = file_path.stat().st_size
- else:
- results['missing_files'].append(file_name)
-
- return results
- def validate_python_syntax() -> Dict[str, Any]:
- """Validate Python syntax of all modules."""
- base_path = Path(__file__).parent
- python_files = list(base_path.glob('*.py'))
-
- results = {
- 'total_files': len(python_files),
- 'valid_files': 0,
- 'invalid_files': [],
- 'syntax_errors': {}
- }
-
- for py_file in python_files:
- try:
- with open(py_file, 'r', encoding='utf-8') as f:
- content = f.read()
-
- # Compile to check syntax
- compile(content, str(py_file), 'exec')
- results['valid_files'] += 1
-
- except SyntaxError as e:
- results['invalid_files'].append(py_file.name)
- results['syntax_errors'][py_file.name] = str(e)
- except Exception as e:
- results['invalid_files'].append(py_file.name)
- results['syntax_errors'][py_file.name] = f"Error reading file: {e}"
-
- return results
- def validate_imports_structure() -> Dict[str, Any]:
- """Validate import structure without actually importing (to avoid PyTorch dependency)."""
- base_path = Path(__file__).parent
-
- results = {
- 'modules_checked': 0,
- 'import_structures': {},
- 'potential_issues': []
- }
-
- # Check __init__.py for proper exports
- init_file = base_path / '__init__.py'
- if init_file.exists():
- try:
- with open(init_file, 'r', encoding='utf-8') as f:
- content = f.read()
-
- # Count imports and exports
- import_lines = [line for line in content.split('\n') if line.strip().startswith('from .')]
- export_lines = [line for line in content.split('\n') if '__all__' in line or line.strip().startswith('"')]
-
- results['import_structures']['__init__.py'] = {
- 'import_count': len(import_lines),
- 'has_all_exports': '__all__' in content,
- 'content_length': len(content)
- }
-
- except Exception as e:
- results['potential_issues'].append(f"Error reading __init__.py: {e}")
-
- # Check other key modules
- key_modules = ['detector.py', 'config.py', 'integration.py']
- for module_name in key_modules:
- module_file = base_path / module_name
- if module_file.exists():
- try:
- with open(module_file, 'r', encoding='utf-8') as f:
- content = f.read()
-
- # Basic structure analysis
- class_count = content.count('class ')
- function_count = content.count('def ')
- docstring_count = content.count('"""')
-
- results['import_structures'][module_name] = {
- 'class_count': class_count,
- 'function_count': function_count,
- 'docstring_count': docstring_count,
- 'content_length': len(content)
- }
-
- results['modules_checked'] += 1
-
- except Exception as e:
- results['potential_issues'].append(f"Error reading {module_name}: {e}")
-
- return results
- def validate_documentation() -> Dict[str, Any]:
- """Validate documentation completeness."""
- base_path = Path(__file__).parent
-
- results = {
- 'readme_exists': False,
- 'readme_size': 0,
- 'module_docstrings': {},
- 'documentation_coverage': 0.0
- }
-
- # Check README
- readme_file = base_path / 'README.md'
- if readme_file.exists():
- results['readme_exists'] = True
- results['readme_size'] = readme_file.stat().st_size
-
- # Check module docstrings
- python_files = [f for f in base_path.glob('*.py') if f.name != '__pycache__']
- documented_modules = 0
-
- for py_file in python_files:
- try:
- with open(py_file, 'r', encoding='utf-8') as f:
- content = f.read()
-
- # Check for module docstring
- has_module_docstring = content.strip().startswith('"""') or content.strip().startswith("'''")
-
- # Count docstrings
- docstring_count = content.count('"""') + content.count("'''")
-
- results['module_docstrings'][py_file.name] = {
- 'has_module_docstring': has_module_docstring,
- 'docstring_count': docstring_count
- }
-
- if has_module_docstring:
- documented_modules += 1
-
- except Exception as e:
- results['module_docstrings'][py_file.name] = {'error': str(e)}
-
- if python_files:
- results['documentation_coverage'] = documented_modules / len(python_files)
-
- return results
- def generate_system_report() -> Dict[str, Any]:
- """Generate comprehensive system validation report."""
- print("🔍 Validating Trixy Voice Recognition System...")
- print("=" * 60)
-
- # Run all validations
- structure_results = validate_module_structure()
- syntax_results = validate_python_syntax()
- import_results = validate_imports_structure()
- doc_results = validate_documentation()
-
- # Compile overall results
- overall_results = {
- 'structure': structure_results,
- 'syntax': syntax_results,
- 'imports': import_results,
- 'documentation': doc_results,
- 'overall_score': 0.0,
- 'recommendations': []
- }
-
- # Calculate overall score
- structure_score = structure_results['found_files'] / structure_results['total_files']
- syntax_score = syntax_results['valid_files'] / syntax_results['total_files'] if syntax_results['total_files'] > 0 else 0
- doc_score = doc_results['documentation_coverage']
-
- overall_results['overall_score'] = (structure_score + syntax_score + doc_score) / 3
-
- # Generate recommendations
- if structure_results['missing_files']:
- overall_results['recommendations'].append(f"Missing files: {', '.join(structure_results['missing_files'])}")
-
- if syntax_results['invalid_files']:
- overall_results['recommendations'].append(f"Syntax errors in: {', '.join(syntax_results['invalid_files'])}")
-
- if doc_score < 0.8:
- overall_results['recommendations'].append("Improve documentation coverage")
-
- if not doc_results['readme_exists']:
- overall_results['recommendations'].append("Add README.md file")
-
- return overall_results
- def print_validation_report(results: Dict[str, Any]):
- """Print a formatted validation report."""
- print(f"📋 VALIDATION REPORT")
- print("=" * 60)
-
- # Structure validation
- structure = results['structure']
- print(f"📁 MODULE STRUCTURE:")
- print(f" Files found: {structure['found_files']}/{structure['total_files']}")
- if structure['missing_files']:
- print(f" Missing: {', '.join(structure['missing_files'])}")
- print()
-
- # Syntax validation
- syntax = results['syntax']
- print(f"🐍 PYTHON SYNTAX:")
- print(f" Valid files: {syntax['valid_files']}/{syntax['total_files']}")
- if syntax['invalid_files']:
- print(f" Syntax errors: {', '.join(syntax['invalid_files'])}")
- for file, error in syntax['syntax_errors'].items():
- print(f" {file}: {error}")
- print()
-
- # Import structure
- imports = results['imports']
- print(f"📦 IMPORT STRUCTURE:")
- print(f" Modules checked: {imports['modules_checked']}")
- if imports.get('potential_issues'):
- print(f" Issues: {len(imports['potential_issues'])}")
- for issue in imports['potential_issues']:
- print(f" - {issue}")
- print()
-
- # Documentation
- docs = results['documentation']
- print(f"📚 DOCUMENTATION:")
- print(f" README exists: {'✅' if docs['readme_exists'] else '❌'}")
- print(f" Documentation coverage: {docs['documentation_coverage']:.1%}")
- print()
-
- # Overall score
- score = results['overall_score']
- print(f"🎯 OVERALL SCORE: {score:.1%}")
-
- if score >= 0.9:
- print(" Status: ✅ EXCELLENT")
- elif score >= 0.8:
- print(" Status: ✅ GOOD")
- elif score >= 0.7:
- print(" Status: ⚠️ FAIR")
- else:
- print(" Status: ❌ NEEDS IMPROVEMENT")
-
- print()
-
- # Recommendations
- if results['recommendations']:
- print("💡 RECOMMENDATIONS:")
- for i, rec in enumerate(results['recommendations'], 1):
- print(f" {i}. {rec}")
- else:
- print("💡 No issues found - system looks good!")
-
- print("=" * 60)
- def main():
- """Main validation function."""
- try:
- results = generate_system_report()
- print_validation_report(results)
-
- # Return exit code based on overall score
- if results['overall_score'] >= 0.8:
- print("✅ Validation completed successfully!")
- return 0
- else:
- print("⚠️ Validation completed with issues.")
- return 1
-
- except Exception as e:
- print(f"❌ Validation failed with error: {e}")
- import traceback
- traceback.print_exc()
- return 2
- if __name__ == "__main__":
- sys.exit(main())
|