Audio to binary conversion
显示 更早的评论
Hello
i'm working on a project related to steganography ( audio steganography), and at first i want to convert an existing wav file to audio and extract the LSB's of it using a MATLAB script. how can i start?
i used this code:
[filename, pathname] = uigetfile('*.wav', 'Pick an audio');
wavebinary = dec2bin( typecast( single(filename(:)), 'uint8'), 8 ) - '0';
[r c] = size(wavebinary);
wavb= [];
wavd=[];
for k=1:r
wavb=horzcat(num2str(wavebinary(k,1:8),wavb));
x=bin2dec(wavb(1:8));
wavd=horzcat(x,wavd);
wavb=[];
end
wavd=fliplr(wavd);
it gives me a 36*8 martix don't know why
and i need more samples.. how can i do that?
2 个评论
Have you tried bitget()?
it gives Undefined function 'bitget' for input arguments of type 'char'. as i tried to put wavebinary =bitget(filename);
采纳的回答
Your code never reads the file. Your code is transforming the file NAME to binary.
38 个评论
ops looks i got lost somehow with the variables.. i'll change it but if i want to convert the audio to a stream of bits.. can the code give the desired result? i have tried many times.. but i didn't get what i want and can i change the sampling frequency?
[sounddata, fs] = audioread(filename);
wavebinary = dec2bin( typecast( single(soundata), 'uint8'), 8 ) - '0';
I cannot tell what the purpose of the rest of your code is.
The least significant bit of each byte of wavebinary will be
mod(wavebinary, 2)
can you please give me a simple example showing when the file is opened until it's converted to bin? and how much fs is? thanks in advance.
[filename, pathname] = uigetfile('*.wav', 'Pick an audio');
if ~ischar(filename)
return; %user cancel
end
filename = fullfile(pathane, filename);
[sounddata, fs] = audioread(filename);
wavebinary = dec2bin( typecast( single(soundata), 'uint8'), 8 ) - '0';
LSBs = mod(wavebinary, 2);
fs will be whatever is stored in the .wav file as the sampling frequency: it is not something that you input.
it works on a small size file but why does it give an error when a larger file selected? Error using typecast The first input argument must be a vector.
they must be the same in everything but in size
wavebinary = dec2bin( typecast( single(soundata(:)), 'uint8'), 8 ) - '0';
The problem is not that the files were large, but rather that they were stereo.
would you please tell me what should i add to convert any of them to bin?
The code I posted converts them to binary.
thanks for your help.. i appreciate it.
Hello, can you please help me to reverse a binary matrix to a wav file?
i used to the previous code that you gave me in order to convert from the wav to binary matrix thank you.
The code I gave previously,
wavebinary = dec2bin( typecast( single(soundata(:)), 'uint8'), 8 ) - '0';
converts to an N x 8 numeric array. If you embedded that into a file, you would have had to do so as a vector, which would have require that you choose a sequence to use the bits from the array -- which could have been that you went across the rows so that all information from a particular sample is grouped together, or it could have been that you went down the columns, as that would be the normal MATLAB order of addressing the bits.
I think it likely that if you are having difficulty reversing the line of code I showed here, that you are probably also having difficulty getting the extracted bits together into the proper order to turn back into sound. In order for us to help you with that, you will have to describe the order that the wavebinary bits were stored in the file.
Is the size of the sound that you embed a constant, or are you also embedding bits indicating what the size is? You need the size information in order to extract the information properly. At the very least you need to know how many channels and you need to know the point at which the embedding stops so that you do not end up extracting bits that were never set.
Sara MH
2018-1-7
编辑:Walter Roberson
2018-1-7
using the code that you have provided, i converted a .wav file with a size of 25.6 KB (26,302 bytes), as written in its properties, to the matrix:
wavebinary <52516x8 double>, as written in the workspace in MATLAB. now i want to re-shape a modified version of this matrix to a .wav file again.
hope this clarified things to you.
Sara MH
2018-1-7
编辑:Walter Roberson
2018-1-7
And the matrix that i want to reshape ((call it wavebinary2)) into .wav has the same number of bytes ( <52516x8 doublr.> , as the wavebinary now i want to reshape it again into .wav file
the size doesn't appear with double, it is 52516x8
sounddata2 = reshape( double( typecast(bin2dec( char(wavebinary2 + '0')), 'single') ), size(sounddata) );
and now you can use audiowrite() on that, being sure to specify the fs when you write.
the following error appears,
Error using reshape
To RESHAPE the number of elements must not change.
Error in MainSS (line 39)
stego_audio = reshape( double( typecast(bin2dec( char(stego_wavebinary + '0')),
'single') ), size(sounddata) );
Please show class(sounddata), size(soundata), size(wavebinary), size(stego_wavebinary)
sure:
1- class(sounddata) : double
2- size(soundata)= 13129 1
3-size(wavebinary) =52516 8
4-size(stego_wavebinary)=52516 8
stego_audio = reshape(double(typecast(uint8(bin2dec( char(stego_wavebinary + '0'))),'single')), size(sounddata));
i know i've asked much about this :D .. but i used audiowrite after specifying fs:
StegoAudio= audiowrite(stego_audio,y,fs);
and the error says:
Error using audiowrite
Too many output arguments.
Error in MainSS (line 44)
StegoAudio= audiowrite(stego_audio,y,fs);
audiowrite does not accept any output arguments. It writes to a file. You can fopen() the file to read it as binary, or you can audioread() the file if you want to check the contents.
so audioread() can convert the stego_audio to .wav?
No, audioread() reads back from audio files. audiowrite converts data to .wav files.
if i want to call the new wav: stego (( stego.wav)) so is this the right code?
stego= audiowrite(stego_wavebinary,y,fs);
audiowrite('stego.wav', stego_wavebinary, fs);
thank you it worked! but i get distorted file with a longer time although i i changed the lsb and it has the same fs as the original one but the stego.wav size is much larger as w .wav file
when i convert this file again into a matrix ( stego_wavebinary2) its number of bytes resulted 32 times of it before conversion ( stego_wavebinary2= 32*stego_wavebinary)
The size of the audio file itself depends upon compression, which the original might have used but the new version probably did not.
Or are you referring to what shows up for "bytes" when you use whos() ?
"bytes" are about the size of the matrices i'm coverting
Could you confirm that you are referring to bytes from the whos output for the variables, not looking at what MS Windows reports for the file size of the .wav file? And that the matrices show up as the same size()? What class() shows up for them?
in the extraction process, i opened the file (stego) to obtain the matrix sounddata2 and then stego_binary2 to start extraction. check the following:
[filename, pathname] = uigetfile('*.wav', 'Pick an audio');
if ~ischar(filename)
return; %user cancel
end
filename = fullfile(pathname, filename);
[sounddata2, fs] = audioread(filename);
stego_wavebinary2 = dec2bin( typecast( single(sounddata2(:)), 'uint8'), 8 ) - '0';
size(stego_wavebinary2)
size(sounddata2)
answers:
1680512 8
ans =
52516 8
stego has the same frequency as the input file (fs=8192) the input file was 1 second long but stego is 6 seconds long
before converting it to .wav , the matrix was called stego_wavebinary and it was exactly the same size as the original wavebinary (obtained from sounddata matrix)
summarizing the sizes:
1.sounddata = 13129 1
2. wavebinary = 52516 8
3.stego_wavebinary= 52516 8
4.stego_audio = 13129 1
and then stego_audio was converted to audio .. to be later converted to sounddata2 and then stego_wavebinary2 which are shown in previous comments.
all the matrices are double
audiowrite('stego.wav', stego_audio, fs);
can i contact you? i want some help in this
Walter Roberson
2018-1-12
编辑:Walter Roberson
2018-1-12
No, I prefer questions to be posted in public. Also, I am not interested in steganography itself.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
