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)

FILE INPUT OR OUTPUT


#  1. If You Want Creat a New File So
a = open("manan.txt", "w")
a.close()

#  2. if you want write on this file so

b = open("manan.txt", "w")
c = b.write("Hello Manan")
b.close()

# 3. If You Want Again Write In File So Used Append (a) If You Used Appand Write The text And text Is Add
# End Of The Text Of Is File.

d = open("manan.txt", "a")
e = d.write("\nYou Are Run The Program")
d.close()

#  An Other Method You Want Add text In File

with open('manan.txt', 'a')as f:
    f.write("\nHard Work In Pyhtone")

#  4. If You Want Read The Lines Of Folder So

g = open("manan.txt", "r")
while True:
    line = g.readlines()
    if not line:
        break
    print (line)

    #  5. If You Want User Input and Autamtically Save In File So

    age = int(input("Enter Your Age: "))
    h = open("manan.txt", "a")
    h.write(age)
    h.close()

OS LIBRARY FUNCTIONS

 

import os

#  1. if you want access the directory  of is current file so

# print(os.getcwd())

# 2. if you want a creat folder in current folder so

# os.mkdir("Test Folder")

# 3. if you want check the exsist of folder so

# print(os.path.exists("Test Folder"))

# 4. if function in is

# if os.path.exists('Test Folder'):
#     print("Already Exists")
# else:
#     print(os.mkdir("Manan"))

# 5. when if we want creat folder in another directory of is PC so

# os.mkdir(r"D:\Import Folder/hanan.txt")

# 6. if you want again folder creat in hanan.txt so

# os.mkdir(r"D:\Import Folder\hanan.txt/wahab.txt")

# 7. if you want access the list of current directory so

# print(os.listdir())

# 8. if you want access the list of another directory so

# print(os.listdir(r"D:\Import Folder"))

#  9. if you want access the folder path so

# for item in os.listdir():
#     path = os.path.join(os.getcwd(),item)
#     print(path)

#  10. if you want access another directory path so

# for item in os.listdir("D:\Import Folder"):
#     path = os.path.join("D:\Import Folder", item)
#     print(path)

#  11. if you want creat a list in folder so
# for i in range(0, 101):
#     os.mkdir(f"D:\Folders/Data {i}")

# 11. if you want change the name of files import folder to data so
 
# for i in range(0, 101):
#     os.rename(f"D:\Import Folder {i}", f"D:\Data {i}")
 
# 12. if you want access the folder list of list so

# manan = os.listdir("D:\Folders")
# print(manan)

#  13. if you want folder see in line by line so

# for hanan in manan:
#     print(hanan)

# 14. if you want see this content in all folders in one by one so

# manan = os.listdir("D:\Folders/")
# for hanan in manan:
#     print(os.listdir(f"D:\Folders/{hanan}"))
#     print(hanan)

# 15. if you want change the drictory of current directory so

# print(os.getcwd())

MAKE A CALANDER

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