Uberi / speech_recognition

Speech recognition module for Python, supporting several engines and APIs, online and offline.
https://pypi.python.org/pypi/SpeechRecognition/
BSD 3-Clause "New" or "Revised" License
8.46k stars 2.4k forks source link

Библиотека speech_recognition не видит модуль recognize_google #753

Open DarkiDuke opened 6 months ago

DarkiDuke commented 6 months ago

Я готовлю школьный проект на тему тг бот для перевода голосовых сообщений в текст. Столкнулся с такой проблемой: Библиотека speech_recognition не находит модуль recognize_google Вот мой код: from aiogram import Bot, Dispatcher, types, F from aiogram.filters import CommandStart import speech_recognition as sr import subprocess import asyncio import os

TOKEN = '6833504641:AAGgqsg2XhlqLAYsyev5sI-L08TmZ0VojXU' bot = Bot(TOKEN) dp = Dispatcher() r = sr.Recognizer()

@dp.message(CommandStart()) async def start_command(message: types.Message): await message.answer('Привет! Отправь мне аудиофайл и я конвертирую его в текст!')

@dp.message(F.audio) async def conveerting_audio_to_text(message: types.Message): split_tup = os.path.splitext(message.audio.file_name) file_name = f'{splittup[0]}{message.from_user.full_name}-{split_tup[1]}' await bot.download(message.audio.file_id, file_name)

file_name_wav = f'{split_tup[0]}_{message.from_user.full_name}.wav'
subprocess.call(['ffmpeg', '-i', file_name, file_name_wav])

with sr.AudioFile(file_name_wav) as source:
    audio = r.record(source)
text = r.recognize_google(audio, language='ru')
await message.answer(text)

os.remove(file_name)
os.remove(file_name_wav)

async def main(): await bot.delete_webhook(drop_pending_updates=True) await dp.start_polling(bot)

if name == 'main': asyncio.run(main())