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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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