def analyze_speech_proficiency(self, transcription: str, audio_file_path: str = None,assessment_type: str = 'general') -> Dict:
try:
audio_analysis = self._analyze_audio_characteristics(audio_file_path) if audio_file_path else {}
text_analysis = self._analyze_text_proficiency(transcription, assessment_type)
combined_analysis = self._combine_analyses(text_analysis, audio_analysis, transcription)
return combined_analysis
except Exception as e:
print(f"❌ Speech proficiency analysis error: {e}")
raise
def _create_proficiency_prompt(self, transcription: str, assessment_type: str) -> str:
return f"""
You are a world-renowned English language proficiency expert and certified TESOL instructor with 20+ years of experience. You are known for providing detailed, professional analysis like a premium English tutor.
ASSESSMENT TYPE: {assessment_type}
TRANSCRIPTION TO ANALYZE: "{transcription}"
Provide a comprehensive professional English assessment following this EXACT format:
## PRONUNCIATION ANALYSIS
[Detailed analysis of pronunciation quality, clarity, accent, stress patterns, intonation, and specific sounds. Be specific about what sounds good and what needs improvement.]
## VOCABULARY ASSESSMENT
[Analyze vocabulary range, sophistication, word choice appropriateness, and lexical diversity.]
- Advanced words used: [list specific advanced words they used]
- Vocabulary level: [beginner/intermediate/advanced with explanation]
- Suggested word upgrades: [specific examples like "good → excellent"]
## GRAMMAR EVALUATION
[Assess grammar accuracy, sentence structure complexity, tense usage, and error patterns.]
- Grammar strengths: [specific examples of correct usage]
- Areas for improvement: [specific grammar points to work on]
- Sentence complexity: [analysis of their sentence structures]
## FLUENCY ANALYSIS
[Evaluate speech flow, hesitations, filler words, pace, natural rhythm, and speaking rate]
- Filler words detected: [count and list them]
- Speaking rate assessment: [words per minute if calculable]
- Flow quality: [detailed assessment]
## COHERENCE & ORGANIZATION
[Assess logical flow, idea connection, topic development, clarity of expression]
## CEFR LEVEL ASSESSMENT
CEFR Level: [A1, A2, B1, B2, C1, or C2]
Level Description: [Beginner/Elementary/Intermediate/Upper-Intermediate/Advanced/Proficient]
## DETAILED PROFESSIONAL FEEDBACK
[Provide encouraging, detailed feedback like a professional English tutor. Be specific about their current abilities and growth potential.]
## PRIORITY FOCUS AREAS
[List the top 2-3 areas they should focus on immediately for maximum improvement]
Be detailed, professional, encouraging, and specific. Provide the kind of analysis a student would get from a premium English tutor.
"""
def provide_coaching(self, user_input: str, practice_type: str, topic: str, user_level: str) -> Dict:
try:
coaching_prompt = self._create_coaching_prompt(user_input, practice_type, topic, user_level)
coaching_response = self._get_ai_response(coaching_prompt)
parsed_coaching = self._parse_coaching_response(coaching_response)
return parsed_coaching
except Exception as e:
print(f"❌ Coaching error: {e}")
return self._generate_fallback_coaching(user_input, practice_type)
def _create_coaching_prompt(self, user_input: str, practice_type: str, topic: str, user_level: str) -> str:
return f"""
You are an expert English fluency coach with 15+ years of experience helping students improve their speaking skills. You specialize in providing constructive, encouraging, and actionable feedback.
PRACTICE TYPE: {practice_type}
TOPIC: {topic}
USER LEVEL: {user_level}
USER INPUT: "{user_input}"
Provide comprehensive coaching feedback following this EXACT format:
## IMMEDIATE FEEDBACK
[Provide immediate positive reinforcement and acknowledgment of their effort]
## CORRECTIONS
[List specific corrections needed with explanations]
- Original: [what they said]
- Corrected: [how it should be said]
- Explanation: [why this correction is needed]
## PRONUNCIATION NOTES
[Specific pronunciation feedback and tips]
## VOCABULARY ENHANCEMENT
[Suggest better word choices or more advanced vocabulary]
- Instead of: [basic word/phrase]
- Try using: [advanced alternative]
- Example: [sentence using the advanced word]
## GRAMMAR IMPROVEMENTS
[Point out grammar issues and provide corrections]
## FLUENCY TIPS
[Specific tips to improve natural flow and reduce hesitations]
## CULTURAL CONTEXT
[Explain any cultural nuances or more natural expressions]
## PRACTICE SUGGESTION
[Specific practice exercise based on their performance]
## ENCOURAGEMENT
[Motivational message highlighting their progress and strengths]
Provide specific, actionable feedback that helps them improve their English fluency naturally and confidently.
"""
def generate_practice_prompt(self, practice_type: str, topic: str, level: str) -> Dict:
"""
Generate practice prompts for different types of exercises
"""
prompts = {
'conversation': self._get_conversation_prompts(topic, level),
'pronunciation': self._get_pronunciation_prompts(level),
'vocabulary': self._get_vocabulary_prompts(topic, level),
'storytelling': self._get_storytelling_prompts(topic, level),
'debate': self._get_debate_prompts(topic, level),
'presentation': self._get_presentation_prompts(topic, level),
'song_analysis': self._get_song_prompts(level)
}
return prompts.get(practice_type, prompts['conversation'])