google-cloud-storage - 从 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 上找到的,但是在解决谷歌云库的导入错误后,我想在其中添加一些功能
解决方案
您应该尝试将 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 运行时,它成功且没有错误。
推荐阅读
- python - 具有稳定值的 Matplotlib 颜色映射映射
- java - 过滤并返回结果 Springboot、Spring Jpa、Hibernate Thymeleaf
- typescript - 如何创建高级类型
- wso2 - 如何将 24 小时格式时间转换为 12 小时格式作为 WSO2 ESB 中的属性
- kubernetes - Kubernetes 的秘密真的是秘密吗?
- bash - 用于连接到 Solaris 服务器上的数据库的 Shell 脚本
- jquery - Datatable bfilter true 没有找到匹配的数据
- partitioning - 如何在 Android 固件中将分区 rom CN/ROW 更改为 FUSE - Lenovo A3000-H
- angular - Angular 中子组件的问题
- java - Spring Cloud Gateway - 读取响应正文并设置响应标头