【问题标题】:MSYS - PyAudio Greek lettersMSYS - PyAudio 希腊字母
【发布时间】:2021-07-16 11:17:10
【问题描述】:

MSYS PyAudio 模块:

counter = 1
for i in range (0,self.numdevices):
    if self.p.get_device_info_by_host_api_device_index(0,i).get('maxOutputChannels')>0:
        self.output_devices.append([counter,i,str(self.p.get_device_info_by_host_api_device_index(0,i).get('name'))])
        counter += 1

如果路径中有希腊字母,则显示不正确。

代码:

Χρήστος@Chris-pc MINGW64 /c/python/scripts/Papinhio player/src/main/python_files
$ python
Python 3.8.9 (default, Apr 13 2021, 15:54:59)  [GCC 10.2.0 64 bit (AMD64)] on wi
n32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyaudio
>>> p = pyaudio.PyAudio()
>>> info = p.get_host_api_info_by_index(0)
>>> numdevices = info.get('deviceCount')
>>> for i in range(0,numdevices):
...     print(p.get_device_info_by_host_api_device_index(0,i).get('name'))
...
Microsoft Sound Mapper - Input
Ìéêñüöùíï (FHD Webcam)
Microsoft Sound Mapper - Output
Ç÷åßá / ÁêïõóôéêÜ (Realtek High
>>> for i in range(0,numdevices):                                      '))
...     print(p.get_device_info_by_host_api_device_index(0,i))       )))))
...
{'index': 0, 'structVersion': 2, 'name': 'Microsoft Sound Mapper - Input', 'host
Api': 0, 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency'
: 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defau
ltHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}
{'index': 1, 'structVersion': 2, 'name': 'Ìéêñüöùíï (FHD Webcam)', 'hostApi': 0,
 'maxInputChannels': 2, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.09,
'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defaultHighOu
tputLatency': 0.18, 'defaultSampleRate': 44100.0}
{'index': 2, 'structVersion': 2, 'name': 'Microsoft Sound Mapper - Output', 'hos
tApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency
': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defa
ultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}
{'index': 3, 'structVersion': 2, 'name': 'Ç÷åßá / ÁêïõóôéêÜ (Realtek High', 'hos
tApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency
': 0.09, 'defaultLowOutputLatency': 0.09, 'defaultHighInputLatency': 0.18, 'defa
ultHighOutputLatency': 0.18, 'defaultSampleRate': 44100.0}

【问题讨论】:

  • 每个帖子一个问题。
  • 好的,但我认为这是同样的问题。
  • 我建议您将问题最小化,因为有 2 个不同的库:1) 验证获取字母的库是否使用正确的编码读取它,在修复该错误之后,您只需分析问题是否扩散到 Qt。也许这个问题与 Qt 无关,只是包含它会增加不必要的复杂性
  • @eyllanesc 我在问题的第二部分找到了解决方案(现在已删除):1)我设置 windows 环境变量:设置MSYS=enable_pcon 2)我在self.app.addLibraryPath(r"C:/Python/Lib/site-packages/qt5_applications/Qt/plugins/imageformats") 添加 imageformats 目录(注意,上面的路径不是来自安装在msys中的python,而是来自直接安装在windows中的python 3.9,但是所有这些都不能解决pyaudio设备编码错误。
  • @eyllanesc 代码已添加。

标签: python encoding pyaudio msys


【解决方案1】:

我更改C:\msys64\mingw64\lib\python3.8\site-packages\PyAudio-0.2.11-py3.8-mingw.egg\pyaudio.py的第994行

来自

用于 ["utf-8", "cp1252"] 中的编解码器:

成为:

对于 ["cp1253", "cp1252", "utf-8"] 中的编解码器:

【讨论】:

  • 这并没有解决问题。 Τα Windows δεν έχουν πρόβλημα με τα ελληνικά。问题是一开始就使用 ASCII 代码页。 StackOverflow 在 Windows 上运行,但我输入希腊文本没有问题。鉴于 Python 3 使用 Unicode,那些硬编码的代码页导致问题,它们并没有解决这些问题。即使for codec in ["utf-8", "cp1252"]: 也不应该有任何需要。当字符串已经是 Unicode 时,不需要 utf-8。在阅读非 Unicode 文本时,不能假设它是 Latin1
  • 您使用的是 ASCII 版本的 PortAudio 吗?还是为 ASCII 而不是 Unicode 编译库?
  • 我用的是:pacman -S mingw-w64-x86_64-portaudio, https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
猜你喜欢
  • 2021-07-02
  • 2014-12-21
  • 1970-01-01
  • 2018-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-28
  • 2017-07-22
相关资源
最近更新 更多