Skip to content

"We could not parse the JSON body of your request." with tts-1-(hd) endpoint, text to speach #1141

Closed
@zopyx

Description

@zopyx

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

I am receiving this error (suddenly) with openai==1.12.0 on Feb 09, 2024...worked the day before:


  File "/Users/ajung/Dropbox/FILMORA- VIDEOS/Typesense-Onkopedia - 2/convert.py", line 66, in <module>
    text_to_speech(content, "de", output_wav)
  File "/Users/ajung/Dropbox/FILMORA- VIDEOS/Typesense-Onkopedia - 2/convert.py", line 17, in text_to_speech
    response = client.audio.speech.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ajung/Dropbox/FILMORA- VIDEOS/Typesense-Onkopedia - 2/lib/python3.12/site-packages/openai/resources/audio/speech.py", line 81, in create
    return self._post(
           ^^^^^^^^^^^
  File "/Users/ajung/Dropbox/FILMORA- VIDEOS/Typesense-Onkopedia - 2/lib/python3.12/site-packages/openai/_base_client.py", line 1201, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ajung/Dropbox/FILMORA- VIDEOS/Typesense-Onkopedia - 2/lib/python3.12/site-packages/openai/_base_client.py", line 889, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/Users/ajung/Dropbox/FILMORA- VIDEOS/Typesense-Onkopedia - 2/lib/python3.12/site-packages/openai/_base_client.py", line 981, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", 'type': 'invalid_request_error', 'param': None, 'code': None}}

To Reproduce

import sys
from openai import OpenAI
import openai

client = OpenAI()

SPEED = 1.0
VOICE = "echo"
MODEL="tts-1",
#MODEL="tts-1-hd",

def text_to_speech(content: str, language: str, output_wav: str):

    response = client.audio.speech.create(
        model=MODEL,
        voice=VOICE,
        speed=SPEED,
        input=content,
    )

    print(f"Saved to {output_wav}")
    response.stream_to_file(output_wav)


text_to_speech("hello world", "de", "output.wav")

Code snippets

No response

OS

MacOS Soama

Python version

3.12

Library version

open 1.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions