Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

似乎不支持转发 TTS api 的接口?Invalid URL (POST /audio/speech) #19

Open
Jackiexiao opened this issue Nov 8, 2023 · 0 comments

Comments

@Jackiexiao
Copy link

Jackiexiao commented Nov 8, 2023

from pathlib import Path
from openai import OpenAI


# replace https://api.openai.com to access from china
base_url = "https://xxx.cc/proxy"
api_key = "sk-xxx"

client = OpenAI(
    api_key=api_key,
    base_url=base_url,
)

speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
    model="tts-1",
    voice="alloy",
    input="Today is a wonderful day to build something people love!",
)

response.stream_to_file(speech_file_path)
print(f"Done! See {speech_file_path}")

报错

Traceback (most recent call last):
  File "/Users/jackiexiao/code/openai_tts/demo_tts.py", line 17, in <module>
    response = client.audio.speech.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jackiexiao/anaconda3/lib/python3.11/site-packages/openai/resources/audio/speech.py", line 71, in create
    return self._post(
           ^^^^^^^^^^^
  File "/Users/jackiexiao/anaconda3/lib/python3.11/site-packages/openai/_base_client.py", line 1055, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jackiexiao/anaconda3/lib/python3.11/site-packages/openai/_base_client.py", line 834, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/Users/jackiexiao/anaconda3/lib/python3.11/site-packages/openai/_base_client.py", line 877, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: Error code: 404 - {'error': {'message': 'Invalid URL (POST /audio/speech)', 'type': 'invalid_request_error', 'param': None, 'code': None}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant