Bajardi uzoqov rustam

Muhammad AL Xorazmiy nomidagi Toshkent Axborot tEXNOLOGIYALAR UNIVERSITETI
SIGNALLAR VA TIZIMLAR fanidan
AMALIY ISH
BAJARDI UZOQOV RUSTAM
package task3;
import javax.sound.sampled.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
public class school{
private static TargetDataLine targetDataLine;
private static final File outputFile = new File("recorded_music.wav");
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
createAndShowGUI();
});
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("Oddiy dastur spektral tahlil");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 240);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JButton button1 = createButton("Ovoz yozib olish", "#154574", e -> ovozYozish());
JButton button2 = createButton("DKO'", "#748200", e -> dctt());
JButton button3 = createButton("DFO'", "#748100", e -> fftt());
JButton button4 = createButton("DVO'", "#748105", e -> veyvlet());
JButton button5 = createButton("Spektr", "#748110", e -> spektralTahlil());
JButton button6 = createButton("Chiqish", "#457454", e -> exitProgram());
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
panel.add(button5);
panel.add(button6);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.setVisible(true);
}
private static JButton createButton(String text, String backgroundColor, ActionListener actionListener) {
JButton button = new JButton(text);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
button.setMaximumSize(new Dimension(200, 30));
button.setBackground(Color.decode(backgroundColor));
button.addActionListener(actionListener);
return button;
}
private static void ovozYozish() {
System.out.println("Recording voice message...");
try {
AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Line not supported");
return;
}
targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
targetDataLine.open(audioFormat);
targetDataLine.start();
Thread captureThread = new Thread(() -> {
try {
AudioInputStream audioInputStream = new AudioInputStream(targetDataLine);
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, outputFile);
System.out.println("Recording complete. Voice message saved to: " + outputFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
});
captureThread.start();
Thread.sleep(20000);
captureThread.interrupt();
targetDataLine.stop();
targetDataLine.close();
} catch (LineUnavailableException | InterruptedException e) {
e.printStackTrace();
}
}
private static void dctt() {
System.out.println("DKO' method logic");
}
private static void fftt() {
System.out.println("DFO' method logic");
}
private static void veyvlet() {
System.out.println("DVO' method logic");
}
private static void spektralTahlil() {
System.out.println("Spektr method logic");
}
private static void exitProgram() {
System.exit(0);
}
}
|