# Batching with an array of strings on TTS models

**URL:** <https://community.openai.com/t/batching-with-an-array-of-strings-on-tts-models/527227>\
**Category:** API\
**Tags:** feedback, rate-limit, tts, feature-request, audio\
**Created:** [November 26, 2023, 11:45am UTC](https://community.openai.com/t/batching-with-an-array-of-strings-on-tts-models/527227 "2023-11-26T11:45:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sps](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sps/32/7736_2.png) [@sps](https://community.openai.com/u/sps)\
**Post date:** [November 26, 2023, 11:45am UTC](https://community.openai.com/t/batching-with-an-array-of-strings-on-tts-models/527227/1 "2023-11-26T11:45:51Z")

</div>

Hi,

I would like to do TTS for a large amount of my data; however, my rate limits (RPM) for TTS models are low.

The TPM, however, is adequate for the purpose. Upon trying to use my TPM with batching by passing an array of strings as input, I get the following error:

```auto
Exception has occurred: BadRequestError
Error code: 400 - {'error': {'message': '1 validation error for Request\nbody -> input\n str type expected (type=type_error.str)', 'type': 'invalid_request_error', 'param': None, 'code': None}}
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://api.openai.com/v1/audio/speech'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400

During handling of the above exception, another exception occurred:

  File "/Users/sukhmanjawa/Projects/py-tes/ssml.py", line 9, in <module>
    response = client.audio.speech.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
openai.BadRequestError: Error code: 400 - {'error': {'message': '1 validation error for Request\nbody -> input\n str type expected (type=type_error.str)', 'type': 'invalid_request_error', 'param': None, 'code': None}}

```

Is batching supported on the TTS endpoint?

---

<div class="post-metadata">

**Author:** ![Foxalabs](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/foxalabs/32/738355_2.png) [@Foxalabs](https://community.openai.com/u/Foxalabs)\
**Post date:** [November 26, 2023, 11:58am UTC](https://community.openai.com/t/batching-with-an-array-of-strings-on-tts-models/527227/2 "2023-11-26T11:58:06Z")

</div>

Does not look like it 🤔 I have a contact who knows the speech and vision people, I’ll see if they can find out.

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [November 26, 2023, 6:02pm UTC](https://community.openai.com/t/batching-with-an-array-of-strings-on-tts-models/527227/3 "2023-11-26T18:02:12Z")

</div>

> [@sps](#):
>
> passing an array of strings

The API reference says input is only a string.

> input (string) - Required  
> The text to generate audio for. The maximum length is 4096 characters.

The error you show is sending something other than a string in that position (an array, which only works on “completion”)

Rate limits for `tts-1` are 100-500 per minute, certainly suitable for parallel processing.

`tts-1-hd` - at 3 requests per minute across tiers, is the only one where you wouldn’t have the ability to run lots of parallel jobs and it would be more suited to one at a time with a wait for the next minute after those three.

---

<div class="post-metadata">

**Author:** ![sps](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sps/32/7736_2.png) [@sps](https://community.openai.com/u/sps)\
**Post date:** [November 27, 2023, 7:47am UTC](https://community.openai.com/t/batching-with-an-array-of-strings-on-tts-models/527227/4 "2023-11-27T07:47:01Z")

</div>

I don’t have those rate limits, which is the reason I posted here.

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [November 27, 2023, 8:35am UTC](https://community.openai.com/t/batching-with-an-array-of-strings-on-tts-models/527227/5 "2023-11-27T08:35:20Z")

</div>

Clarify: Are you somehow free of rate limits, or overly-restricted?

**tts-1**  
Free: 3 RPM 200 RPD  
Tier 1,2: 50 RPM  
Tier 3,4: 100 RPM  
Tier 5: 500 RPM

Do you just need techniques to make parallel async or threaded calls?

* * *

You can simulate a “batch”, joining your text up to the character limit, using silence detection after reception, and prompting for a pause longer than would appear in anything being read.

example:

```auto
prompt = """
. The error you show is sending something other than a
string in that position (an array, which only works on “completion”).
[pause for 5 seconds] [another pause]
Rate limits for tts-1 are 100-500 per minute, 
certainly suitable for parallel processing.
""".strip().replace('\n', " ")

```

[Resulting audio](https://whyp.it/tracks/140049/pause-demonstration-tts-1-shimmer-20231127?token=PafSL) (good for 24 hours)

---

<div class="post-metadata">

**Author:** ![sps](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/sps/32/7736_2.png) [@sps](https://community.openai.com/u/sps)\
**Post date:** [November 27, 2023, 10:14am UTC](https://community.openai.com/t/batching-with-an-array-of-strings-on-tts-models/527227/6 "2023-11-27T10:14:47Z")

</div>

My rate limits for `tts-1` is 3 RPM.

Initially I also thought of the silence detection for batching but there are points in the audio (due to the nature of audio I’m generating), where the model generates pauses on its own - which could cause problems with the audio segmentation.

Another is obviously the cost; inserting pauses as you suggest wouldn’t be economic, given the current pricing.

My use case is generating small but numerous segments of audio and such pauses will add to cost.
