Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DarkiDuke opened this issue May 3, 2024 · 0 comments

Comments

@DarkiDuke
Copy link

Я готовлю школьный проект на тему тг бот для перевода голосовых сообщений в текст.
Столкнулся с такой проблемой: Библиотека 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'{split_tup[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())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant