現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Audio to binary conversion
4 ビュー (過去 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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)
