nipponjo/tts_arabic

NameError: 'sd' is not defined in core.py of tts_arabic package

Yasien99 opened this issue · 4 comments

Description

I encountered a NameError when using the tts function from the tts_arabic package. The error indicates that the sd module (presumably sounddevice) is not defined in core.py.

Steps to Reproduce

  1. Install the tts_arabic package.

  2. Run the following code:

    from tts_arabic import tts
    
    # Vocalized input
    text = "اَلسَّلامُ عَلَيكُم يَا صَدِيقِي."
    wave = tts(text, speaker=2, pace=0.9, play=True)
    
    # Buckwalter transliteration
    text = ">als~alAmu Ealaykum yA Sadiyqiy."
    wave = tts(text, speaker=0, play=True)
    
    # Unvocalized input
    text_unvoc = "القهوة مشروب يعد من بذور البن المحمصة"
    wave = tts(text_unvoc, play=True, vowelizer='shakkelha')

Expected Behavior

The text-to-speech conversion should complete successfully, and the audio should be played without any errors.

Actual Behavior

The following error is encountered:

  • NameError: name 'sd' is not defined

This error originates from the play_wave function in core.py:

def play_wave(wave, sr, blocking=False):
    sd.play(wave, samplerate=sr, blocking=blocking)

image

Hi, do you have sounddevice installed? The import is skipped otherwise:

try:
    import sounddevice as sd
except:
    pass

I will add a message for this case.

Yes I pip install the sounddevice-0.4.7, but I kept getting this error

I don't get this problem, did you restart the kernel after installing/updating?

I found that the problem was in colab itself since it doesn't support portaudio and I was suppose to install portaudio19
using this command

!apt-get install -y portaudio19-dev

Since Google Colab does not support direct audio playback, I can save the audio to a file and then play it using the IPython.display module. Then I used this code to run

import sounddevice as sd
import numpy as np
from scipy.io.wavfile import write
from IPython.display import Audio, display
from tts_arabic import tts

def play_audio(audio_data, samplerate):
    write("output.wav", samplerate, audio_data)
    display(Audio("output.wav"))

# Example usage
text = "اَلسَّلامُ عَلَيكُم يَا صَدِيقِي."
wave = tts(text, speaker=2, pace=0.9, play=False)  # Set play=False to prevent automatic playback
play_audio(wave, 22050)  # Assuming the samplerate is 22050 Hz

Thanks for your time and effort.