import speech_recognition as sr
'''
Аудио в текст (audio to text)
pip install SpeechRecognition
'''
audio_file = "audio.wav"
lang_file = "ru" # https://cloud.google.com/speech-to-text/docs/speech-to-text-supported-languages
recognizer = sr.Recognizer()
with sr.AudioFile(audio_file) as source:
audio = recognizer.record(source)
try:
text = recognizer.recognize_google(audio, language=lang_file)
print(text)
except sr.UnknownValueError:
print('Error! Unknown.')
except sr.RequestError as e:
print(f'Error! {e}')
Для работы этого кода:
Примечания:
Альтернативные подходы:
*текст*
- жирный,
~текст~
- курсивный,
-текст-
- _текст_
- подчеркнутый