p0n1 / epub_to_audiobook

EPUB to audiobook converter, optimized for Audiobookshelf
MIT License
1.06k stars 106 forks source link

Inaccurate Chinese Text Length Calculation in OPENAI TTS Service Causes API to Return `'code': 'text_too_long'` #82

Closed eMUQI closed 1 month ago

eMUQI commented 1 month ago

When using the OPENAI TTS service, the character counting for Chinese text appears to be inaccurate, resulting in the API returning the error code 'text_too_long'.

I have encountered this issue consistently when attempting to use the OpenAI TTS service with Chinese text. Despite setting the max_chars parameter in openai_tts_provider.py to half of the stated maximum limit (2048 out of 4096), I still receive the 'text_too_long' error.

According to the OpenAI documentation (https://platform.openai.com/docs/api-reference/audio/createSpeech#audio-createspeech-input), the maximum length for the input text is 4096 characters:

The text to generate audio for. The maximum length is 4096 characters.

I am unclear on how the term 'characters' is defined in this context. For example, in different encoding formats, a single Chinese character can occupy two (UTF-16) or three (UTF-8) characters. Could someone clarify this for me?

Additionally, should we consider this discrepancy in the split_text function to handle Chinese text more accurately?

Thank you for your assistance.

eMUQI commented 1 month ago

I apologize for any confusion. After switching to a different OpenAI proxy service provider, I found that the issue did not reoccur. Upon reviewing the code used by the previous service provider's relay platform, it appears that the problem was with the relay platform itself.

https://github.com/songquanpeng/one-api/blob/f9774698e9a59823a65c0ede475e28c29638f396/relay/controller/audio.go#L53

p0n1 commented 1 month ago

I apologize for any confusion. After switching to a different OpenAI proxy service provider, I found that the issue did not reoccur. Upon reviewing the code used by the previous service provider's relay platform, it appears that the problem was with the relay platform itself.

https://github.com/songquanpeng/one-api/blob/f9774698e9a59823a65c0ede475e28c29638f396/relay/controller/audio.go#L53

Nice. Thanks for letting me know. Is OpenAI feature still working? Maybe I should update the OpenAI SDK later. The Minecraf...Village stuff looks like a phishing account. Just ignore its post and don't click the link.