OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

'generator' object has no attribute 'sample_width'

  • Thread starter Thread starter Butinos
  • Start date Start date
B

Butinos

Guest
I have an error with elevenlabs API:

Code:
Traceback (most recent call last):
  File "", line 34, in <module>
    play(audio)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\playback.py", line 64, in play
    _play_with_pyaudio(audio_segment)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\playback.py", line 23, in _play_with_pyaudio
    stream = p.open(format=p.get_format_from_width(seg.sample_width),
AttributeError: 'generator' object has no attribute 'sample_width'

Code:
from elevenlabs import play
from elevenlabs.client import ElevenLabs
from pydub import AudioSegment 
from pydub.playback import play 

client = ElevenLabs(
  api_key="ELEVEN_API_KEY", # Defaults to ELEVEN_API_KEY
)

audio = client.generate(
text="Hello! 你好! Hola! नमस्ते! Bonjour! こんにちは! مرحبا! 안녕하세요! Ciao! Cześć! Привіт! வணக்கம்!",
voice="Rachel",
model="eleven_multilingual_v2"
)

play(audio)

This code was copied from elevenlabs documentation, i've already fixed few errors. Help me pls!

i tried to find the solution on the internet, but i didn't find anything.
<p>I have an error with elevenlabs API:</p>
<pre><code>Traceback (most recent call last):
File "", line 34, in <module>
play(audio)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\playback.py", line 64, in play
_play_with_pyaudio(audio_segment)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\playback.py", line 23, in _play_with_pyaudio
stream = p.open(format=p.get_format_from_width(seg.sample_width),
AttributeError: 'generator' object has no attribute 'sample_width'
</code></pre>
<pre><code>from elevenlabs import play
from elevenlabs.client import ElevenLabs
from pydub import AudioSegment
from pydub.playback import play

client = ElevenLabs(
api_key="ELEVEN_API_KEY", # Defaults to ELEVEN_API_KEY
)

audio = client.generate(
text="Hello! 你好! Hola! नमस्ते! Bonjour! こんにちは! مرحبا! 안녕하세요! Ciao! Cześć! Привіт! வணக்கம்!",
voice="Rachel",
model="eleven_multilingual_v2"
)

play(audio)
</code></pre>
<p>This code was copied from elevenlabs documentation, i've already fixed few errors.
Help me pls!</p>
<p>i tried to find the solution on the internet, but i didn't find anything.</p>
 

Latest posts

M
Replies
0
Views
1
Mohit Pant
M
Top