Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import numpy as np
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
from matplotlib.animation import FuncAnimation, PillowWriter
|
5 |
import scipy.io.wavfile as wavfile
|
|
|
6 |
|
7 |
# Constants for sound generation
|
8 |
SAMPLE_RATE = 48000
|
@@ -11,7 +12,7 @@ COLUMN_DURATION = 1 # Duration of each column in seconds
|
|
11 |
# Mapping of matrix numbers to musical notes
|
12 |
notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
|
13 |
note_map = {2: "A", 3: "A#", 4: "B", 5: "C", 6: "C#", 7: "D", 8: "D#", 9: "E",
|
14 |
-
10: "F", 11: "F#", 12: "G", 13: "G#"
|
15 |
|
16 |
def generate_tone(note, duration):
|
17 |
"""Generates a tone for a specified note and duration."""
|
@@ -174,7 +175,7 @@ def create_animation(matrix):
|
|
174 |
|
175 |
# Save the animation to a GIF file
|
176 |
gif_path = "matrix_animation.gif"
|
177 |
-
ani.save(gif_path,
|
178 |
plt.close(fig)
|
179 |
|
180 |
return gif_path
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
from matplotlib.animation import FuncAnimation, PillowWriter
|
5 |
import scipy.io.wavfile as wavfile
|
6 |
+
import os
|
7 |
|
8 |
# Constants for sound generation
|
9 |
SAMPLE_RATE = 48000
|
|
|
12 |
# Mapping of matrix numbers to musical notes
|
13 |
notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
|
14 |
note_map = {2: "A", 3: "A#", 4: "B", 5: "C", 6: "C#", 7: "D", 8: "D#", 9: "E",
|
15 |
+
10: "F", 11: "F#", 12: "G", 13: "G#"]
|
16 |
|
17 |
def generate_tone(note, duration):
|
18 |
"""Generates a tone for a specified note and duration."""
|
|
|
175 |
|
176 |
# Save the animation to a GIF file
|
177 |
gif_path = "matrix_animation.gif"
|
178 |
+
ani.save(gif_path, writer=PillowWriter(fps=1))
|
179 |
plt.close(fig)
|
180 |
|
181 |
return gif_path
|