이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Audio to binary conversion
조회 수: 6 (최근 30일)
이전 댓글 표시
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
Sara MH
2017년 12월 26일
it gives Undefined function 'bitget' for input arguments of type 'char'. as i tried to put wavebinary =bitget(filename);
채택된 답변
Walter Roberson
2017년 12월 26일
Your code never reads the file. Your code is transforming the file NAME to binary.
댓글 수: 38
Sara MH
2017년 12월 26일
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?
Walter Roberson
2017년 12월 26일
[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)
Sara MH
2017년 12월 26일
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.
Walter Roberson
2017년 12월 26일
[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.
Sara MH
2017년 12월 26일
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
Walter Roberson
2017년 12월 26일
wavebinary = dec2bin( typecast( single(soundata(:)), 'uint8'), 8 ) - '0';
The problem is not that the files were large, but rather that they were stereo.
Sara MH
2018년 1월 6일
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.
Walter Roberson
2018년 1월 7일
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
Walter Roberson
2018년 1월 7일
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.
Sara MH
2018년 1월 7일
편집: Walter Roberson
2018년 1월 7일
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) );
Walter Roberson
2018년 1월 7일
Please show class(sounddata), size(soundata), size(wavebinary), size(stego_wavebinary)
Sara MH
2018년 1월 7일
sure:
1- class(sounddata) : double
2- size(soundata)= 13129 1
3-size(wavebinary) =52516 8
4-size(stego_wavebinary)=52516 8
Walter Roberson
2018년 1월 7일
stego_audio = reshape(double(typecast(uint8(bin2dec( char(stego_wavebinary + '0'))),'single')), size(sounddata));
Sara MH
2018년 1월 8일
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);
Walter Roberson
2018년 1월 8일
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.
Walter Roberson
2018년 1월 8일
No, audioread() reads back from audio files. audiowrite converts data to .wav files.
Sara MH
2018년 1월 8일
if i want to call the new wav: stego (( stego.wav)) so is this the right code?
stego= audiowrite(stego_wavebinary,y,fs);
Sara MH
2018년 1월 8일
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)
Walter Roberson
2018년 1월 8일
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() ?
Walter Roberson
2018년 1월 9일
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?
Sara MH
2018년 1월 9일
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)
Sara MH
2018년 1월 9일
stego has the same frequency as the input file (fs=8192) the input file was 1 second long but stego is 6 seconds long
Sara MH
2018년 1월 9일
편집: Walter Roberson
2018년 1월 9일
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.
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개)
참고 항목
카테고리
Help Center 및 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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
