audio compression (shorten an audio file)

I want to compress an audio file to make it shorter to put in a game for sound effects. I use the following:
[y,Fs]=wavread('blast.wav');
t1=0;% start time
t2=2;% end time
yNew=y((Fs*t1+1):Fs*t2,1);
wavwrite(yNew,Fs,'soundShort.wav');
The compression is fine and 'soundShort.wav' can play. But command sound(wavread('soundShort.wav')) no longer has any sound, though it's runnable. I wonder what goes wrong.

13 commentaires

a - are you really calling the code as
sound('soundShort.wav')
and so are passing a string to the sound method? If I try that (in my version of MATLAB) then I observe a
Error using sound (line 33)
Audio data must be real and floating point.
What happens when you call
sound(yNew, Fs);
instead? Presumably the yNew array has Fs samples...
a a
a a le 7 Déc 2018
Sorry I didn't mean to write sound('soundShort.wav'), rather I used sound(wavread('soundShort.wav')). There's no sound nor error message, but the file itself is playable through a media tool and sounds normal.
Walter Roberson
Walter Roberson le 7 Déc 2018
sound() with only one input assumes 8000 Hz.
a a
a a le 8 Déc 2018
8000 Hz means?
Walter Roberson
Walter Roberson le 8 Déc 2018
8000 samples per second. Fs = 8000 .
a a
a a le 8 Déc 2018
so what's wrong? how to resolve the problem of no sound running sound(wavread('soundShort.wav'))?
Walter Roberson
Walter Roberson le 8 Déc 2018
your original code uses a statement that reads in both the signal and the sampling frequency. You need to do that . Then you need to pass the signal and the sampling frequency to sound() like Geoff posted .
a a
a a le 9 Déc 2018
no, even after i use
[y,Fs]=wavread('soundShort.wav');sound(y,Fs)
there's no sound.
Walter Roberson
Walter Roberson le 9 Déc 2018
What shows up for size(y) and for min(y) and max(y) ?
a a
a a le 9 Déc 2018
size(y)=81162*2
min(y)=-0.78
max(y)=0.85
a a
a a le 9 Déc 2018
ok. after further testing, actually sound(y,Fs) has a sound on win10 but doesn't on winXP. what's wrong with winXP on this point?
Walter Roberson
Walter Roberson le 9 Déc 2018
http://pcauthorities.com/windows-xp/how-to-troubleshoot-sound-problems-in-windows-xp/
a a
a a le 10 Déc 2018
thank you. after reading it, i still don't know what went wrong for my winxp. on my winxp, 'beep' has a sound while 'sound(beep)' doesn't.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Centre d'aide et File Exchange

Question posée :

a a
le 4 Déc 2018

Commenté :

a a
le 10 Déc 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by