from pydub import AudioSegment
import speech_recognition as sr
# Initialize recognizer
recognizer = sr.Recognizer()
# Path to the uploaded audio file
audio_file_path = "2. Art_and_Business.mp3"
wav_file_path = "2. Art_and_Business.wav"
# Convert MP3 to WAV
audio = AudioSegment.from_mp3(audio_file_path)
audio.export(wav_file_path, format="wav")
# Load and recognize the speech from the WAV file
with sr.AudioFile(wav_file_path) as source:
audio_data = recognizer.record(source)
# Transcribe the audio to text
try:
transcription = recognizer.recognize_google(audio_data)
except sr.UnknownValueError:
transcription = "Could not understand the audio"
except sr.RequestError as e:
transcription = f"Error during transcription: {e}"
transcription
Audio habarlarni text ga o'girib yozib beruvchi kod.
Run qilishdan oldin:
pip install SpeechRecognition
pip install pydub
sudo apt-get install ffmpeg
import speech_recognition as sr
# Initialize recognizer
recognizer = sr.Recognizer()
# Path to the uploaded audio file
audio_file_path = "2. Art_and_Business.mp3"
wav_file_path = "2. Art_and_Business.wav"
# Convert MP3 to WAV
audio = AudioSegment.from_mp3(audio_file_path)
audio.export(wav_file_path, format="wav")
# Load and recognize the speech from the WAV file
with sr.AudioFile(wav_file_path) as source:
audio_data = recognizer.record(source)
# Transcribe the audio to text
try:
transcription = recognizer.recognize_google(audio_data)
except sr.UnknownValueError:
transcription = "Could not understand the audio"
except sr.RequestError as e:
transcription = f"Error during transcription: {e}"
transcription
Audio habarlarni text ga o'girib yozib beruvchi kod.
Run qilishdan oldin:
pip install SpeechRecognition
pip install pydub
sudo apt-get install ffmpeg