Project Code
Project Code
# import numpy as np
# import random
# import tkinter as tk
# import matplotlib.pyplot as plt
# random_frequency_range_R = []
# random_frequency_range_L = []
# left_ear_thresholds = []
# right_ear_thresholds = []
# current_frequency_index = 0
# def display():
# print(left_ear_thresholds)
# print(right_ear_thresholds)
# plt.show()
# else:
# print(f"No data collected for {ear_label} ear audiogram.")
# def play_tone(frequency, duration):
# samples = np.linspace(0, duration, int(duration * 44100), endpoint=False)
# tone = 0.5 * np.sin(2 * np.pi * frequency * samples)
# sd.play(tone, 44100)
# sd.wait()
# def next_tone():
# global current_frequency_index
# else:
# current_frequency_index = 0 # Reset the index for the right ear test
# test_button.config(state=tk.DISABLED)
# start_right_ear_button.config(state=tk.NORMAL)
# tone_label.config(text="Left Ear Test Completed")
# test_label.config(text="Testing Right Ear")
# # Enable the finish button after left ear test completion
# finish_button.config(state=tk.NORMAL)
# def start_left_ear_test():
# global current_test_ear
# current_test_ear = 'Left'
# next_tone()
# def start_right_ear_test():
# global current_test_ear
# current_test_ear = 'Right'
# start_right_ear_button.config(state=tk.DISABLED)
# next_tone()
# def yes_button_pressed():
# if current_test_ear == 'Left':
# left_ear_thresholds.append(random_frequency_range_L[current_frequency_index - 1])
# print(left_ear_thresholds)
# if current_test_ear == 'Right':
# right_ear_thresholds.append(random_frequency_range_R[current_frequency_index - 1])
# print(right_ear_thresholds)
# next_tone()
# def no_button_pressed():
# if current_test_ear == 'Left':
# left_ear_thresholds.append(None)
# if current_test_ear == 'Right':
# right_ear_thresholds.append(None)
# next_tone()
# def finish_test():
# tone_label.config(text="Both Ear Tests Completed")
# finish_button.config(state=tk.DISABLED)
# display()
# generate_audiogram(random_frequency_range_L, left_ear_thresholds, "Left")
# generate_audiogram(random_frequency_range_R, right_ear_thresholds, "Right")
# random_frequency_range_L = generate_random_frequencies(min_frequency,
max_frequency, num_frequencies)
# random_frequency_range_R = generate_random_frequencies(min_frequency,
max_frequency, num_frequencies)
# if __name__ == "__main__":
# root = tk.Tk()
# root.title("Hearing Test Application")
# test_frame = tk.Frame(root)
# test_frame.pack()
# root.mainloop()
import sounddevice as sd
import numpy as np
import random
import tkinter as tk
import matplotlib.pyplot as plt
import time
def display():
print("--------------------------------------")
hear = 0
not_hear = 0
for i, threshold in enumerate(thresholds):
if threshold is not None and threshold >= dB_threshold:
hear += 1
else:
not_hear += 1
if hear >= not_hear:
print(f"| At {ear_label} No hearing loss detected.|")
else:
print(f"| At {ear_label} Hearing loss detected.|")
print("-------------------------------------")
plt.show()
else:
print(f"No data collected for {ear_label} ear audiogram.")
def next_tone():
global current_frequency_index
def start_left_ear_test():
global current_test_ear
current_test_ear = 'Left'
next_tone()
def start_right_ear_test():
global current_test_ear
current_test_ear = 'Right'
start_right_ear_button.config(state=tk.DISABLED)
next_tone()
def yes_button_pressed():
if current_test_ear == 'Left':
left_ear_thresholds.append(random_frequency_range_L[current_frequency_index - 1])
print(left_ear_thresholds)
if current_test_ear == 'Right':
right_ear_thresholds.append(random_frequency_range_R[current_frequency_index - 1])
print(right_ear_thresholds)
next_tone()
def no_button_pressed():
if current_test_ear == 'Left':
left_ear_thresholds.append(None)
if current_test_ear == 'Right':
right_ear_thresholds.append(None)
next_tone()
def finish_test():
tone_label.config(text="Both Ear Tests Completed")
finish_button.config(state=tk.DISABLED)
# display()
time.sleep(5)
generate_audiogram(random_frequency_range_L, left_ear_thresholds, "Left")
generate_audiogram(random_frequency_range_R, right_ear_thresholds, "Right")
if __name__ == "__main__":
# def create_new_app(main_app):
# root = tk.Toplevel(main_app)
root = tk.Tk()
root.title("Hearing Test Application")
test_frame = tk.Frame(root)
test_frame.pack(pady=10) # Add padding to the frame
root.mainloop()