首页 > 解决方案 > 从 google.cloud 导入语音 ImportError:DLL 加载失败:Не найдена указанная процедура

问题描述

我想创建一个电报机器人将音频转换为文本格式并将其存储在谷歌云存储中,因为我已经导入了谷歌 coud 库如果你可以看到,其他库已成功导入并且没有错误,除非 google-cloud- Speech/-storage 当我运行脚本时,它返回如下错误消息:

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-cloud-storagegoogle-speech-api

解决方案


您应该尝试将 protobuf 降级到 3.6.0。

install protobuf==3.6.0

或查看emddudley 评论

对于 Windows 7 上的 protobuf-3.6.1-py2.py3-none-any.whl 和 Python 2.7.10(64 位),Lib\site-packages\google\protobuf\pyext_message.pyd 文件不存在。

对于 Windows 7 上的 protobuf-3.6.1-cp36-cp36m-win_amd64.whl 和 Python 3.6.1(64 位),此文件确实存在:

库\站点包\google\protobuf\pyext_message.cp36-win_amd64.pyd

当我在上述 Python 3 环境中从 google.protobuf.pyext import _message 运行时,它成功且没有错误。


推荐阅读