Edward
Edward

Reputation: 1

os.system error: process not found "video.mp4"

I am having trouble finding a way to close a video tab with the os library. I get the following error when i try os.system('TASKKILL /F /IM video.mp4') to close the video .

from gtts import gTTS
import os 
import time 


msg = 'random text'
language = 'en'

obj = gTTS(text=msg, lang=language, slow=False)

obj.save('video.mp4')


os.system('video.mp4')
time.sleep(3)
os.system('TASKKILL /F /IM video.mp4')

Upvotes: 0

Views: 232

Answers (1)

Hirusha Adikari
Hirusha Adikari

Reputation: 149

video.mp4 is the file name. TASKKILL is used to end running applications and video.mp4 is not an application, it is the file opened by the application. You can learn more about TASKKILL from here.

If you have not changed your default media player in windows, it will be opened with Windows Media Player and to kill it, you can use replace this

os.system('TASKKILL /F /IM video.mp4')

with this

os.system('TASKKILL /F /IM wmplayer.exe')

or else, the best option for you is

# install playsound with the command below
# pip install playsound
from playsound import playsound

# Your code
from gtts import gTTS
import os 
import time 
msg = 'random text'
language = 'en'
obj = gTTS(text=msg, lang=language, slow=False)

# Saving as .mp3 or .mav is the best for playaudio
obj.save('video.mp3')

# Play the saved sound with python
playsound('video.mp3')


# NOTE: This is not how you should sort your imports
# 1 -  standard library imports; 2 - related third party imports; 3 - local application/library specific imports; all in alphebetical order

You can find more alteratives to playsound from here and here. but playsound is the most easy and simple method.

Upvotes: 1

Related Questions