Я хочу создать бота телеграммы для преобразования аудио в текстовый формат и сохранения его в облачном хранилище Google, для этого я импортировал библиотеки Google Coud. Если вы могли видеть, другие библиотеки импортируются успешно и без ошибок, если только google-cloud- речь/-хранилище Когда я запускаю скрипт, он возвращает сообщение об ошибке, например:

Traceback (most recent call last):
  File "C:/Users/USER/Documents/python projects/s2t/bot.py", line 9, in 
<module>
    from google.cloud import speech_v1
  File "C:\Users\USER\Documents\python projects\s2t\lib\site- 
packages\google\cloud\speech_v1\__init__.py", line 17, in <module>
    from google.cloud.speech_v1.gapic import speech_client
  File "C:\Users\USER\Documents\python projects\s2t\lib\site- 
packages\google\cloud\speech_v1\gapic\speech_client.py", line 24, in 
<module>
    import google.api_core.gapic_v1.client_info
  File "C:\Users\USER\Documents\python projects\s2t\lib\site- 
packages\google\api_core\gapic_v1\__init__.py", line 16, in <module>
    from google.api_core.gapic_v1 import config
  File "C:\Users\USER\Documents\python projects\s2t\lib\site- 
packages\google\api_core\gapic_v1\config.py", line 27, in <module>
    from google.api_core import retry
  File "C:\Users\USER\Documents\python projects\s2t\lib\site- 
packages\google\api_core\retry.py", line 67, in <module>
    from google.api_core import datetime_helpers
  File "C:\Users\USER\Documents\python projects\s2t\lib\site- 
packages\google\api_core\datetime_helpers.py", line 23, in <module>
    from google.protobuf import timestamp_pb2
  File "C:\Users\USER\Documents\python projects\s2t\lib\site- 
packages\google\protobuf\timestamp_pb2.py", line 7, in <module>
    from google.protobuf import descriptor as _descriptor
  File "C:\Users\USER\Documents\python projects\s2t\lib\site- 
packages\google\protobuf\descriptor.py", line 47, in <module>
    from google.protobuf.pyext import _message
ImportError: DLL load failed: Не найдена указанная процедура.


Here is my code:

from __future__ import unicode_literals
from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler
from telegram.ext import Filters
from telegram.ext.dispatcher import run_async
from telegram import ChatAction
from tinytag import TinyTag
from google.cloud import speech
from google.cloud import storage

from google.cloud.speech import enums
from google.cloud.speech import types
import os
import io

TOKEN = '1048019183:AAFebrbxYt1kz_73M7uSvhL5SC1AOG6NCnk'
PORT = int(os.environ.get('PORT', '5002'))
BUCKET_NAME = 'botkvartal'
ADMIN_CHAT_ID = 123456
updater = Updater(TOKEN)
dispatcher = updater.dispatcher

def start(bot, update):
    bot.send_message(chat_id=update.message.chat_id, text="Пожалуйста, 
воспользуйтесь аудио обращением к нашему боту")


def voice_to_text(bot, update):
    chat_id = update.message.chat.id
    file_name = str(chat_id) + '_' + str(update.message.from_user.id) + 
str(update.message.message_id) + '.ogg'

    update.message.voice.get_file().download(file_name)
    tag = TinyTag.get(file_name)
    length = tag.duration

    speech_client = speech.SpeechClient()

    to_gs = length > 58

    if to_gs:
        storage_client = storage.Client()

        bucket = storage_client.get_bucket(BUCKET_NAME)
        blob = bucket.blob(file_name)
        blob.upload_from_filename(file_name)
        audio = types.RecognitionAudio(uri='gs://' + BUCKET_NAME + '/' + 
file_name)
    else:
        with io.open(file_name, 'rb') as audio_file:
            content = audio_file.read()
            audio = types.RecognitionAudio(content=content)

    config = types.RecognitionConfig(
        encoding=enums.RecognitionConfig.AudioEncoding.OGG_OPUS,
        sample_rate_hertz=tag.samplerate,
        language_code='ru-RU')

    bot.send_chat_action(chat_id=chat_id, action=ChatAction.TYPING)
    response = speech_client.long_running_recognize(config, 
audio).result(timeout=500) \
        if to_gs else \
        speech_client.recognize(config, audio)

    message_text = ''
    for result in response.results:
        message_text += result.alternatives[0].transcript + '\n'

    update.message.reply_text(message_text)
    os.remove(file_name)


def ping_me(bot, update, error):
    if not error.message == 'Timed out':
        bot.send_message(chat_id=ADMIN_CHAT_ID, text=error.message)


start_handler = CommandHandler(str('start'), start)
oh_handler = MessageHandler(Filters.voice, voice_to_text)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(oh_handler)
dispatcher.add_error_handler(ping_me)
updater.start_polling()
updater.idle()

Этот код с открытым исходным кодом, и я нашел его на github, однако я хочу добавить в него некоторые функции после устранения ошибок импорта облачных библиотек Google.

0
Sultan Akhmetbek 12 Ноя 2019 в 10:43
Можете ли вы попробовать pip установить protobuf == 3.6.0? ссылка, комментарий emddudley
 – 
marian.vladoi
12 Ноя 2019 в 12:06
@marian.vladoi, Спасибо!
 – 
Sultan Akhmetbek
12 Ноя 2019 в 18:26
Это сработало для вас?
 – 
marian.vladoi
12 Ноя 2019 в 18:30
@marian.vladoi, абсолютно. я тоже в шоке xD
 – 
Sultan Akhmetbek
12 Ноя 2019 в 18:48
Хорошо, я сделаю это как ответ, и, пожалуйста, проголосуйте за лучшую видимость для сообщества.
 – 
marian.vladoi
12 Ноя 2019 в 19:02

1 ответ

Вам следует попробовать понизить версию protobuf до 3.6.0.

install protobuf==3.6.0

Или проверьте комментарий emddudley:

С protobuf-3.6.1-py2.py3-none-any.whl и Python 2.7.10 (64-разрядная версия) в Windows 7 файл Lib\site-packages\google\protobuf\pyext_message.pyd не существует.

С protobuf-3.6.1-cp36-cp36m-win_amd64.whl и Python 3.6.1 (64-разрядная версия) в Windows 7 этот файл существует:

Lib\site-packages\google\protobuf\pyext_message.cp36-win_amd64.pyd

Когда я запускаю из google.protobuf.pyext import _message в приведенной выше среде Python 3, он выполняется без ошибок.

0
marian.vladoi 12 Ноя 2019 в 19:23