diff --git a/app.py b/app.py index 09a3c69..e232b15 100644 --- a/app.py +++ b/app.py @@ -1,25 +1,58 @@ from PIL import Image from gtts import gTTS from pytesseract import image_to_string +import os -def image_to_sound(path_to_image): +def image_to_sound(image_path, output_sound_path="sound.mp3"): """ - Function for converting an image to sound + Converts an image to speech audio by extracting text from the image + and converting it to sound. + + :param image_path: Path to the image file. + :param output_sound_path: Path where the sound file will be saved. + :return: True if successful, False otherwise. """ try: - loaded_image = Image.open(path_to_image) - decoded_text = image_to_string(loaded_image) - cleaned_text = " ".join(decoded_text.split("\n")) - print(cleaned_text) - sound = gTTS(cleaned_text, lang="en") - sound.save("sound.mp3") - return True - except Exception as bug: - print("The bug thrown while excuting the code\n", bug) - return + # Open and process the image + with Image.open(image_path) as img: + decoded_text = image_to_string(img) + cleaned_text = " ".join(decoded_text.splitlines()) + + if cleaned_text.strip(): + print(f"Extracted text: {cleaned_text}") + sound = gTTS(cleaned_text, lang="en") + sound.save(output_sound_path) + print(f"Sound saved to {output_sound_path}") + return True + else: + print("No text found in the image.") + return False + + except Exception as error: + print(f"An error occurred: {error}") + return False + + +def process_images_in_directory(directory_path): + """ + Processes all image files in a directory, converting each to a sound file. + + :param directory_path: Path to the directory containing image files. + """ + for filename in os.listdir(directory_path): + if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')): + image_path = os.path.join(directory_path, filename) + sound_filename = os.path.splitext(filename)[0] + ".mp3" + sound_path = os.path.join(directory_path, sound_filename) + success = image_to_sound(image_path, sound_path) + if success: + print(f"Processed {filename} successfully.\n") + else: + print(f"Failed to process {filename}.\n") if __name__ == "__main__": - image_to_sound("image.jpg") - input() \ No newline at end of file + directory = "images" # Change this to your directory path + process_images_in_directory(directory) + input("Press Enter to exit...") diff --git a/visaa_prep/mrecw.java b/visaa_prep/mrecw.java new file mode 100644 index 0000000..1c68fda --- /dev/null +++ b/visaa_prep/mrecw.java @@ -0,0 +1 @@ +kadvipsf[agrhj gibr asjobdspieag diff --git a/visaa_prep/ticket_fever.py b/visaa_prep/ticket_fever.py new file mode 100644 index 0000000..5ba6b6f --- /dev/null +++ b/visaa_prep/ticket_fever.py @@ -0,0 +1,7 @@ +t = int(input()) +for _ in range(0,t): + n,m = map(int,(input().split())) + if n>m: + print(n-m) + else: + print(0)