diff --git a/ATM BANKING PYHTON CODE b/ATM BANKING PYHTON CODE new file mode 100644 index 0000000..6483149 --- /dev/null +++ b/ATM BANKING PYHTON CODE @@ -0,0 +1,58 @@ +print('Welcome to Northen Frock Bank ATM') +restart=('Y') +chances = 3 +balance = 67.14 +while chances >= 0: + pin = int(input('Please Enter You 4 Digit Pin: ')) + if pin == (1234): + print('You entered you pin Correctly\n') + while restart not in ('n','NO','no','N'): + print('Please Press 1 For Your Balance\n') + print('Please Press 2 To Make a Withdrawl\n') + print('Please Press 3 To Pay in\n') + print('Please Press 4 To Return Card\n') + option = int(input('What Would you like to choose?')) + if option == 1: + print('Your Balance is £',balance,'\n') + restart = input('Would You you like to go back? ') + if restart in ('n','NO','no','N'): + print('Thank You') + break + elif option == 2: + option2 = ('y') + withdrawl = float(input('How Much Would you like to +withdraw? \n£10/£20/£40/£60/£80/£100 for other enter 1: ')) + if withdrawl in [10, 20, 40, 60, 80, 100]: + balance = balance - withdrawl + print ('\nYour Balance is now £',balance) + restart = input('Would You you like to go back? ') + if restart in ('n','NO','no','N'): + print('Thank You') + break + elif withdrawl != [10, 20, 40, 60, 80, 100]: + print('Invalid Amount, Please Re-try\n') + restart = ('y') + elif withdrawl == 1: + withdrawl = float(input('Please Enter Desired amount:')) + + elif option == 3: + Pay_in = float(input('How Much Would You Like To Pay In? ')) + balance = balance + Pay_in + print ('\nYour Balance is now £',balance) + restart = input('Would You you like to go back? ') + if restart in ('n','NO','no','N'): + print('Thank You') + break + elif option == 4: + print('Please wait whilst your card is Returned...\n') + print('Thank you for you service') + break + else: + print('Please Enter a correct number. \n') + restart = ('y') + elif pin != ('1234'): + print('Incorrect Password') + chances = chances - 1 + if chances == 0: + print('\nNo more tries') + break diff --git a/Audio processing using Pydub b/Audio processing using Pydub new file mode 100644 index 0000000..c76c15c --- /dev/null +++ b/Audio processing using Pydub @@ -0,0 +1,134 @@ +# Import necessary libraries +from pydub import AudioSegment +import speech_recognition as sr + +# Input audio file to be sliced +audio = AudioSegment.from_wav("1.wav") + +''' +Step #1 - Slicing the audio file into smaller chunks. +''' +# Length of the audiofile in milliseconds +n = len(audio) + +# Variable to count the number of sliced chunks +counter = 1 + +# Text file to write the recognized audio +fh = open("recognized.txt", "w+") + +# Interval length at which to slice the audio file. +# If length is 22 seconds, and interval is 5 seconds, +# The chunks created will be: +# chunk1 : 0 - 5 seconds +# chunk2 : 5 - 10 seconds +# chunk3 : 10 - 15 seconds +# chunk4 : 15 - 20 seconds +# chunk5 : 20 - 22 seconds +interval = 5 * 1000 + +# Length of audio to overlap. +# If length is 22 seconds, and interval is 5 seconds, +# With overlap as 1.5 seconds, +# The chunks created will be: +# chunk1 : 0 - 5 seconds +# chunk2 : 3.5 - 8.5 seconds +# chunk3 : 7 - 12 seconds +# chunk4 : 10.5 - 15.5 seconds +# chunk5 : 14 - 19.5 seconds +# chunk6 : 18 - 22 seconds +overlap = 1.5 * 1000 + +# Initialize start and end seconds to 0 +start = 0 +end = 0 + +# Flag to keep track of end of file. +# When audio reaches its end, flag is set to 1 and we break +flag = 0 + +# Iterate from 0 to end of the file, +# with increment = interval +for i in range(0, 2 * n, interval): + + # During first iteration, + # start is 0, end is the interval + if i == 0: + start = 0 + end = interval + + # All other iterations, + # start is the previous end - overlap + # end becomes end + interval + else: + start = end - overlap + end = start + interval + + # When end becomes greater than the file length, + # end is set to the file length + # flag is set to 1 to indicate break. + if end >= n: + end = n + flag = 1 + + # Storing audio file from the defined start to end + chunk = audio[start:end] + + # Filename / Path to store the sliced audio + filename = 'chunk'+str(counter)+'.wav' + + # Store the sliced audio file to the defined path + chunk.export(filename, format ="wav") + # Print information about the current chunk + print("Processing chunk "+str(counter)+". Start = " + +str(start)+" end = "+str(end)) + + # Increment counter for the next chunk + counter = counter + 1 + + # Slicing of the audio file is done. + # Skip the below steps if there is some other usage + # for the sliced audio files. + + +''' +Step #2 - Recognizing the chunk and writing to a file. +''' + + # Here, Google Speech Recognition is used + # to take each chunk and recognize the text in it. + + # Specify the audio file to recognize + + AUDIO_FILE = filename + + # Initialize the recognizer + r = sr.Recognizer() + + # Traverse the audio file and listen to the audio + with sr.AudioFile(AUDIO_FILE) as source: + audio_listened = r.listen(source) + + # Try to recognize the listened audio + # And catch expections. + try: + rec = r.recognize_google(audio_listened) + + # If recognized, write into the file. + fh.write(rec+" ") + + # If google could not understand the audio + except sr.UnknownValueError: + print("Could not understand audio") + + # If the results cannot be requested from Google. + # Probably an internet connection error. + except sr.RequestError as e: + print("Could not request results.") + + # Check for flag. + # If flag is 1, end of the whole audio reached. + # Close the file and break. + if flag == 1: + fh.close() + break diff --git a/Email Slicer b/Email Slicer new file mode 100644 index 0000000..8e05d0e --- /dev/null +++ b/Email Slicer @@ -0,0 +1,5 @@ +email=input("What is the email address:").strip() +user = email[:email.index("@")] +domain = email[email.index("@")+1:] +output = "Your email is {} and your username is {} and domain is {}".format(email,user,domain) +print(output) diff --git a/Image Processing in Python b/Image Processing in Python new file mode 100644 index 0000000..5dd520a --- /dev/null +++ b/Image Processing in Python @@ -0,0 +1,34 @@ +# using matplotlib and numpy + +import matplotlib.image as img +import numpy as npy + +# provide the location of image for reading +m = img.imread("taj.png"); + +# determining the length of original image +w, h = m.shape[:2]; + +# xNew and yNew are new width and +# height of image required +after scaling +xNew = int(w * 1 / 2); +yNew = int(h * 1 / 2); + +# calculating the scaling factor +# work for more than 2 pixel +xScale = xNew/(w-1); +yScale = yNew/(h-1); + +# using numpy taking a matrix of xNew +# width and yNew height with +# 4 attribute [alpha, B, G, B] values +newImage = npy.zeros([xNew, yNew, 4]); + +for i in range(xNew-1): + for j in range(yNew-1): + newImage[i + 1, j + 1]= m[1 + int(i / xScale), + 1 + int(j / yScale)] + +# Save the image after scaling +img.imsave('scaled.png', newImage); diff --git a/Qr code Generator b/Qr code Generator new file mode 100644 index 0000000..f49552c --- /dev/null +++ b/Qr code Generator @@ -0,0 +1,17 @@ +# Import QRCode from pyqrcode +import pyqrcode +import png +from pyqrcode import QRCode + + +# String which represents the QR code +s = "www.geeksforgeeks.org" + +# Generate QR code +url = pyqrcode.create(s) + +# Create and save the svg file naming "myqr.svg" +url.svg("myqr.svg", scale = 8) + +# Create and save the png file naming "myqr.png" +url.png('myqr.png', scale = 6) diff --git a/README.md b/README.md index d819bb3..7939b3b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ # Python-codes small python codes for specific functionalities like Text to speech,Qr code,Speech to text, + + +### this repo contains many useful resources for the python containing multiple ready to use codes + +Contact me on sidraj2019@gmail.com for more info diff --git a/text to speech/pdf to speech b/text to speech/pdf to speech new file mode 100644 index 0000000..0386b4b --- /dev/null +++ b/text to speech/pdf to speech @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +# you will need 2 python libraries +#1. pyttx3 +#2. PyPDF2 + +#Importing the Libraries +import pyttsx3 +import PyPDF2 + +#opening the book into the file reader +book=open('your pdf file location','rb') + +#using pdf reader +pdfreader=PyPDF2.PdfFileReader(book) + +##reading the pages +pages=pdfreader.numPages +#print(pages) +#select the page number that you want python program to narrate +page=pdfreader.getPage(30) + +#extracting the page contents +text=page.extractText() + +#speaking the extracted text +speaker=pyttsx3.init() + +speaker.say(text) + +speaker.runAndWait() diff --git a/text to speech/text to speech b/text to speech/text to speech new file mode 100644 index 0000000..c270d50 --- /dev/null +++ b/text to speech/text to speech @@ -0,0 +1,6 @@ +# install the python module pyttsx3 +import pyttsx3 +speaker=pyttsx3.init() +text=input("Enter the sentence that you want to speak") +speaker.say(text) +speaker.runAndWait()