Week-8 Nlp Lab Program
Week-8 Nlp Lab Program
Requirements
import nltk
import speech_recognition as sr
import os
nltk.download('punkt')
import os
"""
Args:
Returns:
"""
try:
if wav_file_path is None:
audio = AudioSegment.from_mp3(mp3_file_path)
# Export as WAV
audio.export(wav_file_path, format="wav")
return wav_file_path
except Exception as e:
return None
# Example usage
if __name__ == "__main__":
mp3_to_wav(input_mp3, output_wav)
def audio_to_text(mp3_file_path):
"""
Convert MP3 to WAV, then perform speech recognition and NLP processing
"""
try:
wav_file = mp3_to_wav(mp3_file_path)
# Then do speech recognition
recognizer = sr.Recognizer()
audio_data = recognizer.record(source)
text = recognizer.recognize_google(audio_data)
tokens = word_tokenize(text)
return text
except Exception as e:
return None
"""
"""
try:
sentences = sent_tokenize(text)
tts.save(output_file)
return output_file
except Exception as e:
return None
"""
"""
try:
text = file.read()
except Exception as e:
return None
def main():
if choice == '1':
text = audio_to_text(audio_file)
if text:
print("\nConverted Text:")
print(text)
# Save to file
f.write(text)
if result:
if play_choice == 'y':
else:
print("Invalid choice")
if __name__ == "__main__":
main()
Additionally, you'll need FFmpeg installed on your system:
1. Download FFmpeg:
2. Install FFmpeg:
o Click "New" and paste your FFmpeg bin path (e.g., C:\ffmpeg\bin)
4. Verify Installation:
Notes:
1. Audio to Text:
2. Text to Audio: