【问题标题】:Why does text recognition work on the command line but not in Python's postgres function?为什么文本识别可以在命令行上工作,但不能在 Python 的 postgres 函数中工作?
【发布时间】:2021-08-25 07:51:42
【问题描述】:

我在 google 中有典型的 speech_recognition,它在我的服务器上的命令行 python 3 -- Python 3.7.3(默认,2020 年 7 月 25 日,13:03:44)[GCC 8.3.0] 在 Linux 上正常工作。

在命令行中运行良好,例如:

>>> import speech_recognition as sr
>>> r = sr.Recognizer()
>>> with sr.AudioFile('/var/boot/pcm.wav') as source:
...     a=r.record(source)
...     tt=r.recognize_google(a)
...     print(tt)
... 
therapy in motion giving challenge
>>> 

但我需要在 Postgres 函数 plpython3u 中运行它,对于另一种情况 plpython3u 运行良好,例如 Polly AWS python 版本应用程序。

我不工作的代码是:

CREATE OR REPLACE FUNCTION ivr.boot_action1_pyhon(name_file character varying)
 RETURNS character varying
 LANGUAGE plpython3u
AS $function$

import speech_recognition as sr
r = sr.Recognizer()
with sr.AudioFile('/var/boot/pcm.wav') as source:
    a=r.record(source)
    tt=r.recognize_google(a)
    print(tt)

return tt
$function$
;

结果问题是:

SQL Error [38000]: BŁĄD: AttributeError: 'NoneType' object has no attribute 'split'
  Gdzie: Traceback (most recent call last):
  PL/Python function "boot_action1_pyhon", line 7, in <module>
    tt=r.recognize_google(a)
  PL/Python function "boot_action1_pyhon", line 827, in recognize_google
  PL/Python function "boot_action1_pyhon", line 444, in get_flac_data
  PL/Python function "boot_action1_pyhon", line 1182, in get_flac_converter
  PL/Python function "boot_action1_pyhon", line 1216, in shutil_which
funkcja PL/Python "boot_action1_pyhon"

【问题讨论】:

    标签: python postgresql speech-recognition wav


    【解决方案1】:

    这个问题是如此不可复制,以至于无法回答。尽管如此,以下是我的一些猜测。

    首先,做一些print (sys.version),然后print(sr.__version__),确保你可以重新创建一个与它们匹配的本地环境。

    另一件事是a 似乎是None。检查一下。使用os.path.exists('/var/boot/pcm.wav')确保文件/var/boot/pcm.wav存在


    仔细检查回溯后我们可以看到

      PL/Python function "boot_action1_pyhon", line 1182, in get_flac_converter
      PL/Python function "boot_action1_pyhon", line 1216, in shutil_which
    

    它试图找到一个flac转换器可执行文件并在shutil_which失败——大概是shutil.which的一个包装器,相当于shwhich。我找不到recognize_google 的源代码,所以唯一剩下的就是猜测调试这个:你需要在你的系统上安装一些flac 库。

    疑难解答

    1. 找出他们正在使用的 flac 库
    2. 确保在命令行which your_flac_converter 中返回某些内容
    3. 确保在python中shutil.which('your_flac_converter')

    (如果你不熟悉which/shutil,先做一些实验:在终端尝试which shwhich firefox,然后使用python的shutil.which复现)

    【讨论】:

    • 先生 .. 感谢快速回答... 路径和文件没问题 .. azure 和另一个代码在这个 python 中工作得很好。其次,命令行python3中的这个相同的路径和文件也很好用。将这种情况克隆到另一个服务器后,一切都是相同的错误代码相同.. :-( x86_64-pc-linux-gnu 上的 PostgreSQL 11.9 (Debian 11.9-0+deb10u1),由 gcc (Debian 8.3.0-6) 编译8.3.0, 64 位。////// Python 3.7.3(默认,2020 年 7 月 25 日,13:03:44)Linux 上的 [GCC 8.3.0] 键入“帮助”、“版权”、“学分”或“许可证”了解更多信息。
    • second a=r.record(source) pint value (a).---- --- 看起来没有问题.....在我看来在行 tt = r.recognize_google(a)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 1970-01-01
    • 2017-03-10
    • 2020-06-20
    • 1970-01-01
    相关资源
    最近更新 更多