Search code examples
pythontext-to-speechappkitgoogle-text-to-speech

No module named Appkit. If I try to install it in pycharm it keeps saying "ERROR: Command errored out with exit status 1:"


I'm using pycharm for this and I can't seem to figure out how to fix this error.

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
    return self.func(*args)
  File "/Users/syedrishad/PycharmProjects/OpenCVPython/venv/Text To Speech.py", line 44, in Text_to_speech
    playsound('DataFlair.mp3')
  File "/Users/syedrishad/OpenCVPython/lib/python3.8/site-packages/playsound.py", line 55, in _playsoundOSX
    from AppKit     import NSSound
ModuleNotFoundError: No module named 'AppKit'

Here's the code:

## import libraries

from tkinter import *
from gtts import gTTS
from playsound import playsound



################### Initialized window####################

root = Tk()
root.geometry('350x300')
root.resizable(0,0)
root.config(bg = 'ghost white')
root.title('DataFlair - TEXT_TO_SPEECH')


##heading
Label(root, text = 'TEXT_TO_SPEECH' , font='arial 20 bold' , bg ='white smoke').pack()
Label(root, text ='DataFlair' , font ='arial 15 bold', bg = 'white smoke').pack(side = BOTTOM)




#label
Label(root, text ='Enter Text', font ='arial 15 bold', bg ='white smoke').place(x=20,y=60)


##text variable
Msg = StringVar()


#Entry
entry_field = Entry(root,textvariable =Msg, width ='50')
entry_field.place(x=20 , y=100)


###################define function##############################

def Text_to_speech():
    Message = entry_field.get()
    speech = gTTS(text = Message)
    speech.save('DataFlair.mp3')
    playsound('DataFlair.mp3')

def Exit():
    root.destroy()

def Reset():
    Msg.set("")

#Button
Button(root, text = "PLAY" , font = 'arial 15 bold', command = Text_to_speech, width =4).place(x=25, y=140)
Button(root,text = 'EXIT',font = 'arial 15 bold' , command = Exit, bg = 'OrangeRed1').place(x=100,y=140)
Button(root, text = 'RESET', font='arial 15 bold', command = Reset).place(x=175 , y =140)


#infinite loop to run program
root.mainloop()

I'm very confused about this and other people's solutions do not work for me. Any help would be greatly appreciated. I've been trying to fix this for a week now. Oh, and this is not my code. I'm taking a tutorial and this was one of the projects I've been working on.


Solution

  • You don't have AppKit installed. That's why interpreter is complaining about it.

    You have to install the package, there's two possibilities:

    1. In terminal type pip install AppKit

    2. In PyCharm do: Preferences -> Project Interpreter -> click "+" -> type AppKit -> Install Package

    Et voila, it should be working now.