-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (52 loc) · 2.15 KB
/
main.py
File metadata and controls
58 lines (52 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import numpy as np
import math
from scipy.io import wavfile
import funcLib
#make wav file
def generateWav(func, frequency, duration, sample_rate=44100, amplitude=1.0, output_file="output.wav"):
t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
y = func(t, frequency)
wavfile.write(output_file, sample_rate, y.astype(np.float32))
def generateWav2(y,sample_rate=44100, output_file="output.wav"):
wavfile.write(output_file, sample_rate, y.astype(np.float32))
if __name__ == "__main__":
"""
Exemple d'utilisation : fonction sinusoïdale sur l'intervalle [0, 2*pi] pendant 3 secondes
func = lambda t: np.sin(t) # Fonction sinusoïdale
interval = [0, 2 * np.pi] # Intervalle de temps
duration = 3 # Durée en secondes
generateWav(func, interval, duration, output_file="output.wav")
"""
func = funcLib.blaster
#interface
import tkinter as tk
from tkinter import messagebox
def openOutput():
import os
os.startfile("output.wav")
def generateWavButtonClicked():
try:
frequency = float(freq_entry.get())
duration = float(duration_entry.get())
if 0 <= frequency <= 90000 and 0 <= duration <= 60:
generateWav(func,frequency, duration)
messagebox.showinfo("Success", "WAV file generated successfully!")
openOutput()
root.quit()
else:
messagebox.showerror("Error", "Invalid parameter values. Frequency must be in [0, 10 000] and duration in [0, 60].")
except ValueError:
messagebox.showerror("Error", "Invalid input. Please enter valid numbers.")
root = tk.Tk()
root.title("WAV Generator")
freq_label = tk.Label(root, text="Frequency (0 to 90 000):")
freq_label.pack()
freq_entry = tk.Entry(root)
freq_entry.pack()
duration_label = tk.Label(root, text="Duration (0 to 60 seconds):")
duration_label.pack()
duration_entry = tk.Entry(root)
duration_entry.pack()
generate_button = tk.Button(root, text="Generate WAV", command=generateWavButtonClicked)
generate_button.pack()
root.mainloop()