File size: 2,212 Bytes
8ad2ab3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import json
import whisper
from .compute_fluency import compute_fluency_score
def main():
"""
Main function to run fluency analysis on audio files
"""
# Fixed parameters - modify these values directly in the code
audio_file = r"D:\Intern\shankh\audio_samples\obama_short.wav" # Path to your audio file
model_size = "base" # Whisper model size (tiny, base, small, medium, large)
verbose = True # Whether to print detailed results
try:
# Load whisper model
print(f"Loading Whisper model ({model_size})...")
whisper_model = whisper.load_model(model_size)
# Calculate fluency score
print(f"Analyzing fluency for {audio_file}...")
results = compute_fluency_score(audio_file, whisper_model)
# Print summary results
print("\nFluency Analysis Results:")
print(f"- Fluency Score: {results['fluency_score']:.2f}/100")
print(f"- Insight: {results['insight']}")
print(f"- Speech Rate Stability (SRS): {results['SRS']:.2f}/100")
print(f"- Pause Appropriateness (PAS): {results['PAS']:.2f}/100")
# Print verbose results if enabled
if verbose:
print("\nDetailed Metrics:")
print(f"- Words per minute: {results['components']['wpm']:.1f}")
print(f"- Filler word count: {results['components']['filler_count']}")
print(f"- Long pauses: {results['components']['long_pause_count']}")
print(f"- Pitch variation: {results['components']['pitch_variation']:.2f} semitones")
print(f"- Natural Pause Placement: {results['components']['pas_components']['NPP']:.2f}/100")
print(f"- Avoidance of Filler Words: {results['components']['pas_components']['AFW']:.2f}/100")
# Print first 100 characters of transcript
transcript_preview = results['transcript'][:] + "..." if len(results['transcript']) > 100 else results['transcript']
print(f"\nTranscript preview: {transcript_preview}")
except Exception as e:
print(f"Error during analysis: {str(e)}")
return 1
if __name__ == "__main__":
exit(main()) |