Summarization AI using nltk

hi , I’m doing on project that is summarization Ai. using speech recognition , nltk I’m doing this. first of all , user need to speak then the code converts speech to text and it displays the transcribed text. then it will summarize the transcribed text. but one problem happened while executing that is the output of my code simply did transcribing but it didn’t summarize the transcribed text rather than summarizing the transcribed text simply it is showing the whole transcribed text . l don’t know what to do pls can anybody help?
import speech_recognition as sr
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize, sent_tokenize
from collections import defaultdict

def summarize_text(text, num_sentences=1):
# Tokenize the text into sentences
sentences = sent_tokenize(text)

# Tokenize the text into words
words = word_tokenize(text.lower())

# Remove stop words
stop_words = set(stopwords.words('english'))
words = [word for word in words if word.isalnum() and word not in stop_words]

# Calculate word frequencies
word_freq = defaultdict(int)
for word in words:
    word_freq[word] += 1

# Calculate sentence scores based on word frequencies
sentence_scores = defaultdict(int)
for sentence in sentences:
    for word in word_tokenize(sentence.lower()):
        if word in word_freq:
            sentence_scores[sentence] += word_freq[word]

# Get the top 'num_sentences' sentences with highest scores
summary_sentences = sorted(sentence_scores, key=sentence_scores.get, reverse=True)[:num_sentences]
summary = ' '.join(summary_sentences)
return summary

def speech_to_text():
recognizer = sr.Recognizer()
mic = sr.Microphone() # By default, use the default system microphone

with mic as source:
    print("Speak now...")
    audio = recognizer.listen(source)

    text = recognizer.recognize_google(audio)
    return text
except sr.UnknownValueError:
    print("Sorry, could not understand the audio.")
    return ""
except sr.RequestError as e:
    print(f"Request error: {e}")
    return ""

Get speech input

user_input = speech_to_text()

if user_input:
print(“\nTranscribed Text:”)

# Get the summary of the transcribed text
summary = summarize_text(user_input)
print("\nSummary of Transcribed Text:")

Please read the pinned thread and make sure we can see the code with proper formatting, so that we understand how you have structured it.