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

Add response attribute to TextToSpeechClient class #478

Open
jpwroberts opened this issue Feb 10, 2025 · 2 comments · May be fixed by #479
Open

Add response attribute to TextToSpeechClient class #478

jpwroberts opened this issue Feb 10, 2025 · 2 comments · May be fixed by #479
Assignees

Comments

@jpwroberts
Copy link

Feature Description

Ability to query the response headers, specifically to get the request-id.

The client.TextToSpeechClient class doesn't expose the HTTPS response object, nor the request-id. That makes it difficult to populate the previous_request_ids argument to methods such as convert.

Including the response as an attribute would allow generational conditioning from the Python API, as in the code below:

previous_request_ids = deque(maxlen=MAX_REQUEST_IDS)

# The following code is in a loop iterating over the lines of text.

try:
    previous_text = OMIT if is_first_paragraph or len(text) == 1 else ' '.join(text[:line_no])
    next_text = OMIT if is_last_paragraph or len(text) == 1 else ' '.join(text[line_no + 1:])

    previous_request_argument = previous_request_ids if ((len(previous_request_ids) > 0)
                                                         and condition_on_past_generations) else OMIT

    audio = client.text_to_speech.convert(
        voice_id=voice_id,
        optimize_streaming_latency=None,
        output_format=output_format,
        text=line,
        model_id=model,
        voice_settings=settings,
        previous_text=previous_text,
        next_text=next_text,
        previous_request_ids=previous_request_argument,
        pronunciation_dictionary_locators=pronunciation_dictionary_locators
    )
except Exception as e:
    log_exception(e)
    print(e)
    break
else:
    for chunk in audio:
        audio_segments.append(chunk)
    if condition_on_past_generations:
        request_id = client.text_to_speech.response.headers['request-id']    # <------------------
        if request_id:
            previous_request_ids.append(request_id)

Use Case

Passing previous request IDs to the various methods of the TextToSpeechClient object.

The methods accept a previous_request_ids argument, but the class doesn't provide an obvious way to obtain the request IDs.

Alternatives Considered

At the moment I edit client.py to add the attribute:

class TextToSpeechClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper
        self.response = None

then update self.response from _response in each of the methods. I have to make that change again each time the elevenlabs package is updated.

Additional Context

No response

@PaulAsjes
Copy link
Collaborator

Excellent timing, we noticed this as well and are working on a fix right now. Hope to have something out later this week.

@PaulAsjes PaulAsjes closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2025
@PaulAsjes PaulAsjes reopened this Feb 10, 2025
@jpwroberts
Copy link
Author

Thanks :-). The change is quite trivial, but as I generate Windows and Linux versions of my program I have to make the change twice each time.

@AngeloGiacco AngeloGiacco linked a pull request Feb 10, 2025 that will close this issue
@AngeloGiacco AngeloGiacco self-assigned this Feb 11, 2025
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

Successfully merging a pull request may close this issue.

3 participants