Sunday, 23 June 2024

MAKE A CALANDER

 


# 1.  convert calander year and month. your choice month or year , print


while True:
  import calendar
  year = int(input("Please input the year: "))
  month = int(input("Please input the month (1-12): "))
  cal = calendar.month(year, month)

  with open(f"calendar_{year}_{month}.txt", "w") as file:
    file.write(cal)

  choice = input("do you want again see calendar : (y/n)")
  if choice !="y":
   break
print("calander is save!!!!!")

# 2.  just convert calender in year means all months in year is print

while True:

 import calendar

 year = int(input("plaese enter a yaer : "))
 cal = calendar.calendar(year)
 with open(f"calendar_{year}.txt", "w") as file:
    file.write(cal)

 print(f"Calendar saved as calendar_{year}.txt")
 print("calander is save !!!!")
 choice = input("Do You Want Again Use Calander : (y/n)")
 if choice !="y":
   break

Wednesday, 24 April 2024

CONVERT AUDIO TO TEXT

 

  1. Importing Libraries: We start by importing a library called speech_recognition and giving it the alias sr. This library helps us work with speech recognition.
pythonpy code
import speech_recognition as sr
  1. Initializing the Recognizer: Next, we create an object called recognizer from the Recognizer class. This object helps us recognize speech in audio files.
p orecognizer = sr.Recognizer()
  1. Specifying the Audio File: We tell the program where to find the audio file that we want to convert to text. Here, it's named "audio_file.wav".
pytdeaudio_file_path = "audio_file.wav"
  1. Opening and Recording Audio: We open the audio file using sr.AudioFile and record the audio data from it using recognizer.record(source).
pytpy code
with sr.AudioFile(audio_file_path) as source: audio_data = recognizer.record(source)
  1. Converting Audio to Text: We use the recognize_sphinx method of the recognizer object to convert the audio data into text.
pythoopy code
text = recognizer.recognize_sphinx(audio_data)
  1. Saving Recognized Text to File: We open a text file named "recognized_text.txt" in write mode and write the recognized text into it. We also print a message confirming that the text has been saved.
pythoCopy code
with open("recognized_text.txt", "w") as file: file.write(text) print("Text saved to 'recognized_text.txt'")




pip install SpeechRecognition
pip install pocketsphinx

This code uses SpeechRecognition with CMU Sphinx to convert audio to text offline and saves the result to a text file.

#  1. How To Convert Vedio To Audio In Formate Of (wav) .

import speech_recognition as sr
import moviepy.editor as mp

clip = mp.AudioFileClip(r"C:\Users\Taj\Desktop\Manan Python Proggram\motivation.mp4")
clip.write_audiofile("converted.mp3.wav")
   
#  2. How To Convert Audio To Text


recognizer = sr.Recognizer()
audio_file_path = "converted.mp3.wav"

with sr.AudioFile("converted.mp3.wav") as source:
    audio_data = recognizer.record(source)
    text = recognizer.recognize_sphinx(audio_data)

    with open("recognized_text.txt", "w") as file:
        file.write(text)
        print("Text saved to 'recognized_text.txt'")

Tuesday, 23 April 2024

MOVIEPY LIBRARY


#  1. vedio convert to audio

from moviepy.editor import*

clip1 =  VideoFileClip("test1.mp4")
if clip1.audio is not None:
  clip1.audio.write_audiofile("test1.mp3")
else:
  print("Error: Audio not found in clip1")

clip2 =  VideoFileClip("test2.mp4")
if clip2.audio is not None:
  clip2.audio.write_audiofile("test2.mp3")
else:
  print("Error: Audio not found in clip2")


#  2.  convert vedio to without audio

from moviepy.editor import*

clip1 =  VideoFileClip("test1.mp4")
clip1 = clip1.without_audio()
clip1.write_videofile("test1_W.mp4")
print("end")

clip2 =  VideoFileClip("test2.mp4")
clip2 = clip1.without_audio()
clip2.write_videofile("test2_W.mp4")
print("end")


#  3.  convert vedio to another vedio audio


from moviepy.editor import*

video1 = VideoFileClip("test1_W.mp4")
audio1 = AudioFileClip("test2.mp3")

# Set the audio track of video1 using the audio1 clip
final_video = video1.set_audio(audio1)

# Write the final video with the replaced audio to a new file
final_video.write_videofile("test1_new1.mp4")


# 4.  how to add water mark in file

from moviepy.editor import*

clip = (VideoFileClip("test1.mp4"))

txt_clip = TextClip("Manan", fontsize=60, color='black')

txt_clip = txt_clip.set_position('center').set_duration(clip.duration).set_duration(clip.duration)
vedio = CompositeVideoClip([clip, txt_clip])
vedio.write_videofile("output.mp4")

CREAT A SIMPLE CALCULATOR

 

while True:
  name= input("please enter your name: ")
  print("your name is :" ,name )
  num1 = float(input("Enter your first number: "))
  num2 = float(input("enter your second number: "))
  print("press 1 for + \npress 2 for - \npress 3 for * \npress 4 for /")
  choice= int(input("please enter choice between 1-4 : "))
  if choice==1:
    print(num1+num2)
  elif choice==2:
   print(num1-num2)
  elif choice==3:
   print(num1*num2)
  elif choice==4:
   print(num1/num2)
  else:
   print("invalid input :")

CREAT A SIMPLE ATM MACHINE


while True:

 print("\n\n Welcome To AB Bank: \n\n Plaese Insert Your Card: ")

 name = input("Enter Your Name : ")
 print("Your Name Is", name)

 password = (1020)
 balance = (10000)
 choice = 0
 pin = int(input("Enter Your Pin : "))

 if (pin==password):
   while (choice!=4):
    print("\n\n________Menu________")
    print("1 == Balance")
    print("2 == Deposit")
    print("3 == Withdraw")
    print("4 == Cancel")
    choice = int(input("\n Enter Option : "))

    if(choice==1):
     print("Your Balance is = Rs", balance)
    elif(choice==2):
      deposit = int(input("Enter Deposit Amount,Rs: "))
      balance += deposit
      print("\n Deposit Amount Succefully: Rs",balance)
    elif(choice==3):
      withdraw = int(input("Enter Amount To Withdraw : Rs "))
      balance-= withdraw
      print("\n Withdraw Amount: Rs",withdraw)
      print("Total Balance = Rs", balance)
    elif(choice==4):
       print("\n Session Ended!!!!!")
       print('\nThanks For Using AB Bank ATM.....')
   else:
    print("Incorrect Number!!!")
    choice = input("Do You Want Again Use AB Bank ATM : (y/n)")
    if choice!=("y"):
      break

DATA TYPES


# Data Types In Pyhtone

# 1. string: All The a,b,c..... alphabests is callled a string.

a = "hello words"
print(type(a))

# 2. Intigir: All The Numercal Letters Is Called A Intiger Like 1,2,3,4,5,6.....

b = 1
print(type(b))

# 3. float: All The . Vale Is Called Float Like 10.2 or 20.2 or 0.5

c = 20.5
print(type(c))

# 4. complex: Sting and numercal Value Is Called Complex Like This 5x or 8j or 6d

# 5. List: Multipale Values In a List String + Intigir

d = ["apple", "banana", "orange", 5, 10]
print(type(d))

# 6. Tuple: Tuple Values Does Not Changeble. Same As It List

e = ("apple", "banana", "orange", 5, 10)
print(type(e))

# 7. Range:

f = range(6)
print(type(f))

# 8. Mapping : Basically Is Used For Dictionary And Ic Called A Dictionary

g = {"manan":"hanan","age":36}
print(type(g))

# 9. Set Type:

h = {"apple", "banana" "orange", 5, 20}
print(type(h))

# 10. Boolean: whn if you answer in True or False so is called Boolean.

i = {"apple", "banana" "orange", 5, 20}
print("apple" in i)
print(50 in i)

# 11. Binary:

j = b"hello"
print(type(j))

# 12. bytearray:

k = bytearray(8)
print(type(k))

# 13. memoryview:

l = memoryview(bytes(6))
print(type(l))

# 14. None:

m = None
print(type(m))

WHAT IS DICTIONARY


#  collectionof data items or key-values they are seperated commas or closed curly bracket.

dict = {"manan":"human", "cat": "animal"}
print(dict["manan"])

a = {
    10 : "manan",
    20 : "hanan",
    30 : "wahab"
}
print(a[10])

# 10 is a key or manan is a value.

info = {'name': 'manan', 'age':22, "eligible": True}
print(info)
print(info['name'])

#  if you want see the keys of  dictionary so

print(info.keys())
print(info.values())

#  for fumction in dictionary

for key in info:
    print(f"the value of {key} is {info[key]}")

#  method of dictionary is .update() he is used for combining multiple dictionaries.

c = {10:20, 30:40, 50:60}
d = {70:80, 80:90, 100:110}
c.update(d)
print(c)

# if you want delete the the key-value so use .pop()

d.pop(100)
print(d)

MAKE A CALANDER

  # 1.  convert calander year and month. your choice month or year , print while True :   import calendar   year = int ( input ( "P...