#hi, im trying to use async method using elevenlabs python package, but i get this errorobject asy
1 messages · Page 1 of 1 (latest)
The error object async_generator can't be used in 'await' expression typically occurs when you try to directly await an asynchronous generator instead of iterating over it. In Python, asynchronous generators need to be iterated using async for.
If the text_to_sound_effects.convert method returns an asynchronous generator, you need to use async for to process its output. Here's an example of how you can modify your code:
async for answer in client_elevenlabs.text_to_sound_effects.convert(
text=data_elevenlabs.get('prompt'),
duration_seconds=data_elevenlabs.get('duration'),
prompt_influence=data_elevenlabs.get('prompt_inf', 0.3)
):
# Process each item yielded by the async generator
print(answer)
This approach ensures that you correctly handle the asynchronous generator. If you're unsure whether the method returns an async generator or a regular coroutine, you may need to check the ElevenLabs Python package documentation or the method's implementation.
okay, then recode this method
async def generate_voice_text_to_sound(client_elevenlabs: AsyncElevenLabs, data_elevenlabs: dict):
answer = await client_elevenlabs.text_to_sound_effects.convert(
text=data_elevenlabs.get('prompt'),
duration_seconds=data_elevenlabs.get('duration'),
prompt_influence=data_elevenlabs.get('prompt_inf', 0.3))
logging.info(answer)
return None