推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
hiwenvv
V2EX  ›  Python

Python 如何获取 C 函数返回的指针所指的内容?

  •  
  •   hiwenvv · Apr 10, 2020 · 3445 views
    This topic created in 2367 days ago, the information mentioned may be changed or developed.
    我查看科大讯飞的语音合成帮助文件,里面有这样一个函数:
    const void * data = QTTSAudioGet(sessionID, &audio_len, &synth_status, &ret);
    我可以正确的输入参数,但是,我不知道如何获取返回的 data,并将它写入到文件里。
    我尝试定义 返回值类型:dll.QTTSAudioGet.restype = ctypes.c_void_p,
    但是还是不知道怎么取出里面的数据。
    有人能帮助我吗?
    5 replies  •  2020-04-12 18:14:22 +08:00
    ysc3839
        1
    ysc3839  
       Apr 10, 2020
    看文档,返回的数据是什么类型。
    hiwenvv
        2
    hiwenvv  
    OP
       Apr 12, 2020
    @ysc3839 看文档,应当是字节流 bytes,具体的,是 WAV 文件的内容。可以进一步提示吗?
    ysc3839
        3
    ysc3839  
       Apr 12, 2020 via Android
    那应该还会返回一个长度的,直接读取就好了。
    hiwenvv
        4
    hiwenvv  
    OP
       Apr 12, 2020
    @ysc3839 问题就出在这里,对我这样的外行来说,我不知道如何写“直接读取”....
    我知道他返回了一个字节流,指针是 那个 C 函数的返回值 data,我也知道函数参数里返回了长度 audio_len 。
    但是我不会写代码啊。我翻了很多页的百度,也没得到我想要的写法,可能是问题太初级而我太弱鸡了...
    ysc3839
        5
    ysc3839  
       Apr 12, 2020 via Android
    这样的话没办法,只能多锻炼搜索能力,我帮你找到了一个
    https://stackoverflow.com/a/55128773
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2576 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 03:07 · PVG 11:07 · LAX 20:07 · JFK 23:07
    ♥ Do have faith in what you're doing.