No worries. We all start from the same place ![]()
With python, indentation is critical. It uses indentation to distinguish blocks of code. I made minor changes to you code.
- imported Path to make it easier to handle file paths.
- set dst from src to make it more dynamic.
Try this (I haven’t tested this though)
import speech_recognition as sr
import time
from pydub import AudioSegment
from pathlib import Path
def convert_audio_to_text(src):
dst = Path(src).with_suffix('.wav')
# convert wav to mp3
audSeg = AudioSegment.from_mp3(src)
audSeg.export(dst, format="wav")
r = sr.Recognizer()
with sr.AudioFile(dst) as source:
# print("Say Something...")
audio = r.listen(source)
try:
print("Reading audio file. Please, wait a moment...")
text = r.recognize_google(audio, language='en-US')
time.sleep(1.5)
print(text)
except:
print("I am sorry! I can not understand!")
convert_audio_to_text('C:\\Users\\TTssRpaConba\\Desktop\\audio.mp3')