65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
import argparse
|
|
from helpers.audio_analysis import UrduIntentExtractor
|
|
import time
|
|
|
|
def main():
|
|
"""
|
|
Command-line interface for Urdu Intent Extractor
|
|
"""
|
|
parser = argparse.ArgumentParser(
|
|
description="Extract intent from Urdu speech using Whisper translation"
|
|
)
|
|
|
|
parser.add_argument(
|
|
"audio_file",
|
|
help="Path to audio file (mp3, wav, m4a, flac, etc.)"
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--model",
|
|
default="base",
|
|
choices=["base", "medium", "large-v1", "large-v2", "large-v3"],
|
|
help="Whisper model size (default: base)"
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--output",
|
|
help="Save results to JSON file"
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--quiet",
|
|
action="store_true",
|
|
help="Minimal output"
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
# Initialize extractor
|
|
extractor = UrduIntentExtractor(model_size=args.model)
|
|
|
|
start_time = time.time()
|
|
# Process audio file
|
|
results = extractor.process_audio_file(
|
|
args.audio_file,
|
|
verbose=not args.quiet
|
|
)
|
|
end_time = time.time()
|
|
print(f"⏱️ Execution time: {(end_time - start_time) / 60:.2f} minutes, {(end_time - start_time)} seconds")
|
|
|
|
# Save to JSON if requested
|
|
if args.output:
|
|
import json
|
|
with open(args.output, 'w', encoding='utf-8') as f:
|
|
json.dump(results, f, ensure_ascii=False, indent=2)
|
|
print(f"\nResults saved to: {args.output}")
|
|
|
|
except FileNotFoundError as e:
|
|
print(f"⏱️ Execution time: {(end_time - start_time) / 60:.2f} minutes, {(end_time - start_time)} seconds")
|
|
print(f"❌ Error: {e}")
|
|
except Exception as e:
|
|
print(f"❌ An error occurred: {str(e)}")
|
|
|
|
if __name__ == "__main__":
|
|
main() |