OSError: libespeak.so.1: cannot open shared object file: No such file or directory | virtual assistant web app

Hello everyone!
This web app is a virtual assistant (takes a sound and does what the user says).
I deploy it on streamlit sharing and it shows me this error so is it possible to run this web app via Streamlit?


app.py file:

#import pywhatkit
from neuralintents import GenericAssistant
import speech_recognition
import pyttsx3 as tts
from quote import quote
import streamlit as st
from random_word import RandomWords
import warnings


warnings.filterwarnings("ignore")


def local_css(file_name):
    with open(file_name) as f:
        st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)


def remote_css(url):
    st.markdown(f'<link href="{url}" rel="stylesheet">', unsafe_allow_html=True)


def icon(icon_name):
    st.markdown(f'<i class="material-icons">{icon_name}</i>', unsafe_allow_html=True)


local_css("style.css")
remote_css('https://fonts.googleapis.com/icon?family=Material+Icons')

st.markdown("<h1 style='text-align: ; color: #FFFAFA;'>Your virtual intelligence assistant</h1>",
            unsafe_allow_html=True)
st.markdown("<h3 style='text-align: ; color: #FFFAFA;'>Click and Say hello!</h3>", unsafe_allow_html=True)
st.info("she's able to do the fllowing: \n - Play Songs. \n - say a wisdom. \n - create todo list. \n - create note. \n - show the todo list. ")
submitButton = st.button("Play")

if submitButton:
    recognizer = speech_recognition.Recognizer()
    speaker = tts.init()
    voices = speaker.getProperty('voices')
    speaker.setProperty('voice', voices[1].id)
    speaker.setProperty('rate', 150)

    todo_list = []


    def create_note():
        global recognizer
        speaker.say('What do you want to write in your notes?')
        speaker.runAndWait()

        done = False

        while not done:
            try:
                with speech_recognition.Microphone() as mic:
                    recognizer.adjust_for_ambient_noise(mic, duration=0.2)
                    audio = recognizer.listen(mic)
                    note = recognizer.recognize_google(audio)
                    note = note.lower()

                    speaker.say("Choose a filename!")
                    speaker.runAndWait()
                    recognizer.adjust_for_ambient_noise(mic, duration=0.2)
                    audio = recognizer.listen(mic)

                    filename = recognizer.recognize_google(audio)
                    filename = filename.lower()

                with open(f"{filename}.text", 'w') as f:
                    f.write(note)
                    done = True
                    speaker.say(f"I successfully created the note {filename}")
                    speaker.runAndWait()
            except speech_recognition.UnknownValueError:
                recognizer = speech_recognition.Recognizer()
                speaker.say("I did not understand you! Please try again")
                speaker.runAndWait()


    def add_todo():
        global recognizer

        speaker.say("What to do do you want to add?")
        speaker.runAndWait()
        done = False

        while not done:
            try:
                with speech_recognition.Microphone() as mic:
                    recognizer.adjust_for_ambient_noise(mic, duration=0.2)
                    audio = recognizer.listen(mic)

                    item = recognizer.recognize_google(audio)
                    item = item.lower()
                    todo_list.append(item)
                    done = True

                    speaker.say(f"I added {item} to the to do list!")
                    speaker.runAndWait()

            except speech_recognition.UnknownValueError:
                recognizer = speech_recognition.Recognizer()
                speaker.say("I did not understand. Please try again")
                speaker.runAndWait()


    def show_todo():
        speaker.say("The item on your to do list are the following")
        for item in todo_list:
            speaker.say(item)
        speaker.runAndWait()


    def hello():
        speaker.say("hello what can i do for you?")
        speaker.runAndWait()


    def quotes():
        print("quote")
        r = RandomWords()
        w = r.get_random_word()

        res = quote(w, limit=1)
        for i in range(len(res)):
            speaker.say("here's a wisdom for today")
            st.info(" a wisdom for today: \n" + res[i]['quote'])
            speaker.say(res[i]['quote'])
            speaker.runAndWait()


    def hate_words():
        global recognizer
        speaker.say("but i love u")
        speaker.runAndWait()
        done = False

        while not done:
            try:
                with speech_recognition.Microphone() as mic:
                    recognizer.adjust_for_ambient_noise(mic, duration=0.2)
                    audio = recognizer.listen(mic)

                    words = recognizer.recognize_google(audio)
                    words = words.lower()
                    speaker.runAndWait()
                    done = True

            except speech_recognition.UnknownValueError:
                recognizer = speech_recognition.Recognizer()
                speaker.say("I did not understand. Please try again")
                speaker.runAndWait()


    def love_words():

        print("love")
        global recognizer
        speaker.say("you're amazing")
        speaker.runAndWait()
        done = False
        while not done:
            try:
                with speech_recognition.Microphone() as mic:
                    recognizer.adjust_for_ambient_noise(mic, duration=0.2)
                    audio = recognizer.listen(mic)

                    word = recognizer.recognize_google(audio)
                    word = word.lower()
                    speaker.runAndWait()
                    done = True

            except speech_recognition.UnknownValueError:
                recognizer = speech_recognition.Recognizer()
                speaker.say("I did not understand. Please try again")
                speaker.runAndWait()


    def play_songs():

        global recognizer

        speaker.say("What do you want to hear?")
        speaker.runAndWait()
        done = False

        while not done:
            try:
                with speech_recognition.Microphone() as mic:
                    recognizer.adjust_for_ambient_noise(mic, duration=0.2)
                    audio = recognizer.listen(mic)

                    song = recognizer.recognize_google(audio)
                    song = song.lower()
                    speaker.say('playing' + song)
                    # pywhatkit.playonyt(song)
                    speaker.runAndWait()
                    done = True

            except speech_recognition.UnknownValueError:
                recognizer = speech_recognition.Recognizer()
                speaker.say("I did not understand. Please try again")
                speaker.runAndWait()

    def quit():
        speaker.say("Bye")
        speaker.runAndWait()
        st.stop()

    mappings = {
            "greeting": hello,
            "create_note": create_note,
            "add_todo": add_todo,
            "show_todo": show_todo,
            "quotes": quotes,
            "play_songs": play_songs,
            "love_words": love_words,
            "hate_words": hate_words,
            "exit": quit}

    assistent = GenericAssistant('intents.json', intent_methods=mappings)
    assistent.train_model()




    while True:
        try:
            with speech_recognition.Microphone() as mic:
                recognizer.adjust_for_ambient_noise(mic, duration=0.2)
                audio = recognizer.listen(mic)
                message = recognizer.recognize_google(audio)
                message = message.lower()

            assistent.request(message)

        except speech_recognition.UnknownValueError:
            recognizer = speech_recognition.Recognizer()
# st.error("please try again")

else:
    pass

requirements file:

quote==2.0.4
pywhatkit==4.1
neuralintents==0.0.4
SpeechRecognition==3.8.1
pyttsx3==2.90
streamlit==0.74.1
Random-Word==1.0.7
RandomWords==0.3.0
PyYAML==5.4.1
1 Like

Hi @lama_Alrweta,

Quick q: can the file be found in your local deployment environment?

Thanks,
Charly

yes it was working in the local host

Ok, thanks for confirming @lama_Alrweta.

It seems like there 's a folder and/or file that can’t be found in Streamlit Sharing.

Can you please check if it’s there?

Thanks,
Charly

Yes the folder was uploaded in GitHub as it was in the local deployment environment.

How can I know what is missing?

You can check in your GH repo if the folder is there.

Charly

yes it’s there

When you have an error that says something to the effect of lib<something>.so, this means that you are missing a system dependency. In your case, you are missing espeak.

Add a packages.txt file to your repo with the following line in it:

libespeak1

Best,
Randy

2 Likes

Thanks this works!
but now I have another problem “AttributeError: Could not find PyAudio; check installation” although I don’t use the PyAudio package