Skip to content

Instantly share code, notes, and snippets.

@hctilg
Created June 23, 2024 14:34
Show Gist options
  • Save hctilg/ed6af1b0940bb3d7758aa372b53badcf to your computer and use it in GitHub Desktop.
Save hctilg/ed6af1b0940bb3d7758aa372b53badcf to your computer and use it in GitHub Desktop.
Sound to Text (fa-IR)
import speech_recognition as sr
from pydub import AudioSegment
audio_file = "your_audio_file_path_here.mp3"
sound = AudioSegment.from_mp3(audio_file)
sound.export("output.wav", format="wav")
recognizer = sr.Recognizer()
with sr.AudioFile("output.wav") as source:
audio_data = recognizer.record(source)
text = recognizer.recognize_google(audio_data, language="fa-IR")
print(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment