AttributeError: ‘HttpxBinaryResponseContent’ 对象没有属性 ‘with_streaming_response’

我在使用 openai 将文本转换为音频时,总是遇到这个错误:AttributeError: ‘HttpxBinaryResponseContent’ 对象没有属性 ‘with_streaming_response’。我尝试过使用 stream_to_field() 函数,但它也不起作用。

def audio(prompt):
    speech_file_path=Path('C:\\Users\\beni7\\Downloads\\proyectos_programacion\\proyecto_shorts\\audio').parent / "speech.mp3"
    response = openai.audio.speech.create(
        model="tts-1",
        voice="alloy",
        input=prompt
    )
    response.with_streaming_response.method(speech_file_path)

回答:

.with_streaming_response 是 speech 上的一个方法。你可以尝试以下方法:

def audio(prompt):
    speech_file_path="<file path>"
    with client.audio.speech.with_streaming_response.create(
        model="tts-1",
        voice="alloy",
        input=prompt,
    ) as response:
        response.stream_to_file(speech_file_path)

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注