Reputation: 31
I am creating a python voice assistant referring from a youtube tutorial. Unfortunately, the video creator has a windows os. So he uses startfile from OS module. But this is not working in ubuntu. Here is the code that the video maker used:
elif 'play music' in query:
music_dir = '/home/thilak/Music'
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[0]))
But this didn't work out for me, so I used this one:
elif 'play music' in query:
music_dir = '/home/thilak/Music'
songs = os.listdir(music_dir)
print(songs)
os.system(os.path.join(music_dir, songs[0])) #changing startfile to system
Still, this code too shows an error message like this:
Say that again please...
Listening....
recognizing...
User said: play music
['Despacito and senorita (copy).mp4', 'Curtis Waters - Stunnin’ (Lyrics) “ I’m a pretty boy,I’m stunning “-YVrha4CjldA.mkv', 'DJ Snake ft. Justin Bieber - Let Me Love You [Lyric Video]-SMs0GnYze34 (copy).mkv', 'Curtis Waters - Stunnin’ (Lyrics) “ I’m a pretty boy,I’m stunning “-YVrha4CjldA (copy).mkv', 'Despacito and senorita.mp4', 'DJ Snake ft. Justin Bieber - Let Me Love You [Lyric Video]-SMs0GnYze34.mkv']
sh: 1: Syntax error: "(" unexpected
Please help me resolve this issue. Thank you!
Upvotes: 2
Views: 215
Reputation: 1128
As given, the code was meant for windows, how about using ffmpeg
's ffplay
elif 'play music' in query:
music_dir = '/home/thilak/Music'
songs = os.listdir(music_dir)
print(songs)
os.popen('ffplay -nodisp -autoexit "'+os.path.join(music_dir, songs[0])+'" >/dev/null 2>&1')
before using the above codes do remember to install ffmpeg using apt
sudo apt-get update
sudo apt-get install ffmpeg
Upvotes: 1