- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我刚刚开始学习 Java,正在开发一个 Java 音频隐写项目(即将文本文件隐藏在 wav 文件中)。
为此,我将文本和 wav 文件存储在两个文件中。现在我想以字节为单位读取它们,并用文本文件位替换 wav 文件的随机位。
如何以字节为单位读取文件? (我尝试过使用InputStream)。是否可以用文本文件的位替换 wav 文件中的随机位?有什么功能可以实现吗?读取文件(文本和 wav 文件)后,如何编辑(和替换)wav 文件的字节?
这是第一个屏幕,当用户点击“隐藏”按钮时,会打开下一个屏幕。
public class OptionScreen extends javax.swing.JFrame {
/** Creates new form OptionScreen */
public OptionScreen() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
hide = new javax.swing.JButton();
unhide = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
hide.setText("Hide");
hide.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
hideActionPerformed(evt);
}
});
unhide.setText("UnHide");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(55, 55, 55)
.addComponent(hide, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(94, 94, 94)
.addComponent(unhide, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(81, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(109, 109, 109)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hide, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(unhide, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(101, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void hideActionPerformed(java.awt.event.ActionEvent evt) {
second s=new second();
s.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new OptionScreen().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton hide;
private javax.swing.JButton unhide;
// End of variables declaration
}
import java.io.DataInputStream;
import java.io.File;
import java.io.File.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
public class second extends javax.swing.JFrame {
private File afile; // put at bottom of class
private File tfile;
/** Creates new form second */
public second() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
text = new javax.swing.JButton();
audio = new javax.swing.JButton();
tname = new javax.swing.JLabel();
aname = new javax.swing.JLabel();
begin = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
text.setText("TEXT FILE");
text.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
textActionPerformed(evt);
}
});
audio.setText("AUDIO FILE");
audio.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
audioActionPerformed(evt);
}
});
begin.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
begin.setText("BEGIN");
begin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
beginActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(87, 87, 87)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(text, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(audio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(tname, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(aname, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addGap(270, 270, 270)
.addComponent(begin, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(31, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(101, 101, 101)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(text)
.addComponent(tname, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(audio)
.addComponent(aname, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(begin, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(19, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void textActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser opentext=new JFileChooser();
opentext.showOpenDialog(this);
int returnVal = opentext.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
tfile = opentext.getSelectedFile();
String tfname=tfile.getName();
tname.setText(tfname);
// ... code that loads the contents of the file in the text area
}
}
private void audioActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser openaudio=new JFileChooser();
openaudio.showOpenDialog(this);
int returnVal = openaudio.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
afile = openaudio.getSelectedFile();
aname.setText(afile.getName());
// ... code that loads the contents of the file in the text area
}
}
private void beginActionPerformed(java.awt.event.ActionEvent evt) {
try {
InputStream fint = new FileInputStream(tfile);
byte []bt=new byte[(int)afile.length()];
InputStream fina = new FileInputStream(afile);
int offset = 0;
int numRead = 0;
//
try {
System.out.println(new DataInputStream(fint).readByte());
} catch (IOException ex) {
Logger.getLogger(second.class.getName()).log(Level.SEVERE, null, ex);
}
//
System.out.println(bt);
//////////////////////////////////////////////////////////////////
FileOutputStream outs=new FileOutputStream(new File("C:\\Documents and Settings\\Administrator\\My Documents\\My Music\\Secret.wav"));
} catch (FileNotFoundException ex) {
}
//end of try catch
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new second().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel aname;
private javax.swing.JButton audio;
private javax.swing.JButton begin;
private javax.swing.JButton text;
private javax.swing.JLabel tname;
// End of variables declaration
}
最佳答案
您有两种方法:(1) 将文件读入字节数组,然后在内存中对其进行操作,然后将其写回磁盘。 (2) 使用 RandomAccessFile 允许您直接操作磁盘上的文件。
关于java - 如何读取 wav 文件并替换其中的位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7146382/
如果已知该确切样本存在于 wav 中的某处(但可能与其他声音混合),是否可以使用 FFT 找到较长 wav 中出现的小 wav 样本? 编辑 (收到两个回复后):如果我有一个包含所有已知声音的库,这些
我对 .NET 中的音频完全陌生,所以请多多包涵。 我的目标是创建一个具有两个 channel 的 wav 文件。左声道将包含语音消息(使用 SpeechSynthesizer 生成的流),右声道需要
我的大部分信息都来自其他stackoverflow帖子,但没有一个真正有用。 import UIKit import AVFoundation class FaceButtonSc
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 3 年前。
这可能是一个非常简单的问题;我将一个单声道 WAV 文件转换为一个 short[] 数组,并且我有一个将其写回 WAV 文件的函数。一切正常。 (writeBuffer 是 short[] 数组) b
我们的应用程序需要知道它加载的音频文件的样本数。我们使用的库可以可靠地确定采样率,但不能确定样本数。我们是否可以仅从文件大小和采样率来计算样本数? 最佳答案 马克说什么。不,通常您需要解释标题。但是,
我正在用java做一个项目,需要我加密wave文件。那么,是否有一个直接的过程可以将波形文件转换为二进制文件并返回?我将对二进制数据应用加密算法。 最佳答案 是的。 File file = new F
我想知道如何从 .wav 文件中获取样本以执行两个 .wav 文件的窗口连接。 谁能告诉我怎么做? 最佳答案 wave标准库的模块是关键:当然在代码顶部的 import wave 之后,wave.op
我有一个几分钟长的 .wav 文件,我想将其分成不同的 10 秒 .wav 文件。 到目前为止,这是我的 python 代码: import wave import math def main(fil
我在 ffmpeg 中使用以下命令合并多个 wav 文件: -f concat -safe 0 -i /storage/emulated/0/AudioClipsForSpeakerRecogniti
我正在尝试用python实现主动降噪。我的项目由两组代码组成: 录音代码 声音过滤代码 我的目标是当您运行该程序时,它将开始通过麦克风录音。录音完成后,会生成一个名为“file1.wav”的保存文件,
我正在尝试制作一个音乐识别系统。我担心我可能没有按照预期读取 wav 样本,而且我可能会应用错误的窗口大小来进行 FFT 和其他操作。 如果你能帮我的话,那就太好了。 首先,我有一些关于 Wavs 中
如何使用 java 合并两个 wav 文件? 我试过了 this但它没有正常工作,他们还有其他方法吗? 最佳答案 如果您直接处理 wav 文件的字节,您可以在任何编程语言中使用相同的策略。对于此示例,
尝试为我的 previous question 找到解决方法,我想将用 byte[](具有 wav header )编写的 16k 8 位单声道 wav 转换为 8k 8 位单声道流/字节 []。 是
目前我正在使用一个语音到文本的翻译模型,该模型采用 .wav 文件并将音频中的可听语音转换为文本转录本。该模型之前曾用于直接录制的 .wav 音频录音。但是现在我正在尝试对视频中最初出现的音频做同样的
试图在 python 中将 wav 文件转换为 wav uLaw。 使用 pydub 的 AudioSegment,我可以使用以下命令转换为 mp3: AudioSegment.from_wav(fr
我在 xcode 项目中添加了 LibFlac。然后我在我的项目中添加了来自 Libflac 的decode/main.c。我通过了 infile.flac 并运行了项目的可执行文件,但它给出了以下错
大家好,感谢您的阅读。 我想使用 Python 的 scipy.io.wavfile 对一首歌进行一些分析。由于我只有 .mp3 格式的歌曲,因此我使用 ffmpeg 将文件转换为 .wav,方法如下
我需要连接两个音频波,以便最终输出的音频波应该有一个更平滑的交汇点。我的意思是,在连接点,假设 10 秒钟,第一个音频应该开始淡出,而另一个音频开始拾取。 我已经能够连接两个音频文件并生成单个输出,但
我需要将一个 wav 文件转换为 8000Hz 16 位单声道 Wav。我已经有一个代码,它适用于 NAudio 库,但我想使用 MemoryStream 而不是临时文件。 using System.
我是一名优秀的程序员,十分优秀!