lugia19 / elevenlabslib

Full python wrapper for the elevenlabs API.
MIT License
150 stars 27 forks source link

sounddevice.PortAudioError #28

Closed Ushi-Oni closed 5 months ago

Ushi-Oni commented 5 months ago

Hey all!

Getting this new error when utilizing generate_stream_audio_v2. I have the following setup for the call:

xi_voice.generate_stream_audio_v2(
        prompt=prompt,
        generationOptions=elevenlabslib.GenerationOptions(
            stability=0.5,
            similarity_boost=0.1,
            style=0.777,
            use_speaker_boost=True,
        ),
        playbackOptions=elevenlabslib.PlaybackOptions(
            runInBackground=True,
            portaudioDeviceID=1,
            onPlaybackEnd=lambda: audio_lock.release()
        )
    )

Error:

sounddevice.PortAudioError: Error opening RawOutputStream: Invalid number of channels [PaErrorCode -9998]

Any ideas?

lugia19 commented 5 months ago

Are you sure device index 1 is an output device? It might be an input. The code just tries to play a 1 channel file (mono) which should be supported by basically anything.

You can do

import sounddevice
sounddevice.query_devices()

To see all the various device IDs.

Ushi-Oni commented 5 months ago

Yep! Exactly what it was. Wrote this quick little blurb to prompt the user so they can setup what device they'd like to use:

print("Next, let's select the proper audio device.")
        p = pyaudio.PyAudio()
        for i in range(p.get_device_count()):
            device_info = p.get_device_info_by_index(i)
            if device_info['defaultSampleRate'] >= 44100.0 and device_info['maxOutputChannels'] > 0:
                print(f'#{device_info["index"]}: {device_info["name"]} \n')
                print(f'@{device_info["defaultSampleRate"]}Hz with default low/high output latency of '
                      f'[{device_info["defaultLowOutputLatency"]},{device_info["defaultHighOutputLatency"]}] \n')
                print('-'*100)
        while audio_device_index == -1:
            try:
                audio_device_index = int(input("Please enter the index id you'd like to select. Choose wisely."))
            except ValueError:
                print('Invalid selection, your input to the previous question was not a number. Try again.')
lugia19 commented 5 months ago

👍, glad to hear that fixed it.

Ushi-Oni commented 5 months ago

Actually, I tried switching to sounddevice, used that to get a good index, and set that for the playback device, but now I'm getting a Failed to Load ASIO driver (ASIO error 0)

Specifically: sounddevice.PortAudioError: Error opening RawOutputStream: Unanticipated host error [PaErrorCode -9999]: 'Failed to load ASIO driver' [ASIO error 0]

lugia19 commented 5 months ago

It appears the support for ASIO can have some problems: https://github.com/spatialaudio/python-sounddevice/issues/442

I would recommend trying one of the other audio backends. I usually use MME if on windows.