LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-10-2009, 01:03 AM   #1
felipe1982
LQ Newbie
 
Registered: Dec 2007
Posts: 23

Rep: Reputation: 0
speex speexenc does not encode an audio file


I have been messing around with speex (speexenc) for a few days, have have been replacing MP3 voice with SPX voice, compressing by an additional 20% (files are 20% smaller). All well. I've been running:
Code:
lame --quite --decode file.mp3 - | speexenc - file.spx
I tried today to decode/encode an mp3 into spx, but I get a strange error onscreen:
Quote:
Only 8 kHz (narrowband) and 16 kHz (wideband) supported (plus 11.025 kHz and 22.05 kHz, but your mileage may vary)
I haven't seen that error before. These are the flags I tried, mixed and matched them as best I could while retaining some sanity
* --le
* --be
* --8bit
* --16bit
* -w
* -u
* -n
* --vad
* --vbr

All gave the SAME error. I am *still* able to modify *other* mp3 files without a problem.

Next, I tried to decode with lame in WAV, and then try speexenc. Nothing.
Code:
lame --decode voice.mp3 voice.wav
And I make sure the file is indeed WAV.
Code:
~$ file voice.wav
 RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 24000 Hz
I've searched google a bit, and mailing lists for speex aren't helpful. Manual also doesn't show anything helpful. Any thoughts?

EDIT: The output for the lame decoding shows
Quote:
input: voice.mp3
(24 kHz, 2 channels, MPEG-2 Layer III)
output: ../WAV/voice.wav
(16 bit, Microsoft WAVE)
skipping initial 1105 samples (encoder+decoder delay)
skipping final 632 samples (encoder padding-decoder delay)
Frame#135030/135030 64 kbps MS
But *other* mp3 files show this when decoding to WAV
Quote:
input: other.mp3
(44.1 kHz, 1 channel, MPEG-1 Layer III)
output: ../WAV/other.wav
(16 bit, Microsoft WAVE)
skipping initial 1105 samples (encoder+decoder delay)
Frame#124035/124067 64 kbps
Do these differences matter? Why can't I encode to speex?

Last edited by felipe1982; 12-10-2009 at 01:18 AM.
 
Old 12-10-2009, 12:34 PM   #2
felipe1982
LQ Newbie
 
Registered: Dec 2007
Posts: 23

Original Poster
Rep: Reputation: 0
any ideas guys why I can't convert this mp3 to speex?
 
Old 12-21-2009, 01:18 AM   #3
felipe1982
LQ Newbie
 
Registered: Dec 2007
Posts: 23

Original Poster
Rep: Reputation: 0
Quote:
Only 8 kHz (narrowband) and 16 kHz (wideband) supported (plus 11.025 kHz and 22.05 kHz, but your mileage may vary)
What does this error mean?
 
Old 06-08-2010, 08:26 PM   #4
rmallins
LQ Newbie
 
Registered: Nov 2005
Location: Hatfield, Herts
Distribution: Ubuntu 10.10
Posts: 13

Rep: Reputation: 1
The reason speexenc is complaining is that the native sample rate of your mp3 file, at 24kHz, is not one of the recommended sample rates for speex. I was just able to speex encode a more typical mp3 (sampled at 44100kHz) using your command, though I still got the same warning message so it looks like speexenc is just rejecting a 24kHz sample rate for some reason.

You can work around the problem by resampling the audio, as I'll demonstrate further down.

Audio mp3s typically use the audio CD sample rate of 44100 samples per second. DVD audio (whether encoded as mp3 or AAC) is typically sampled at 48kHz (the same as the highest quality setting for DAT tapes). The sample rate limits the highest frequency you can reproduce (look up "nyquist frequency" for more info). Speex is designed for human speech, which usually doesn't contain much high frequency information. As a reduction of sample rate reduces the required data rate, speex uses lower sample rates than typically used for music files.

Speex is designed to encode/decode at 8k, 16k or 32k samples per second, so the encoder complains when it's not fed audio to this spec.

mplayer can resample audio, but can't easily output to stdout, so here's how to use mplayer and speexenc tied together with a named pipe/named fifo:

The input file I'm using is 128kbps mp3 (44100Hz sample rate), as shown by file:


rmallins@rmallins-desktop:~/tmp$ file audio_book_disk_1.mp3
audio_book_disk_1.mp3: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, JntStereo
rmallins@rmallins-desktop:~/tmp$


1) create a named fifo and tell mplayer to resample the audio as 16kHz pcm (as used in wav files) to it:

rmallins@rmallins-desktop:~/tmp$ mkfifo named_fifo
rmallins@rmallins-desktop:~/tmp$ mplayer -srate 16000 -ao pcm:file=named_fifo audio_book_disk_1.mp3


(you could equally well use -srate of 32000 or 8000 here for speex and get respectively better or worse final sound quality )
mplayer will now be blocked having almost immediately filled the fifo and be waiting to write data to it, so we need a new process to run speexenc to read data from the fifo:

2) start a new shell in the same directory, and make speexenc encode data from the fifo:

rmallins@rmallins-desktop:~/tmp$ speexenc named_fifo audio_book_disk_1_16kHz.spx


After hitting return you'll notice activity in both shells, as mplayer is now able to write to the fifo as speexenc reads data from it.

Afterwards you'll find your speex encoded (and dramatically smaller) file:

rmallins@rmallins-desktop:~/tmp$ ll -h
total 83M
-rw-r--r-- 1 rmallins rmallins 16M 2010-06-09 02:16 audio_book_disk_1_16kHz.spx
-rw-r--r-- 1 rmallins rmallins 67M 2010-06-09 01:27 audio_book_disk_1.mp3
prw-r--r-- 1 rmallins rmallins 0 2010-06-09 02:16 named_fifo
rmallins@rmallins-desktop:~/tmp$


Now the named_fifo can be deleted.
 
Old 06-08-2010, 10:19 PM   #5
felipe1982
LQ Newbie
 
Registered: Dec 2007
Posts: 23

Original Poster
Rep: Reputation: 0
Hey. thanks for answering this ancient post. I had actually forgotten about it, and written off. I shall try your suggestions. Thank you.
 
Old 06-30-2010, 10:26 AM   #6
Ken_Fallon
LQ Newbie
 
Registered: Nov 2005
Distribution: Debian
Posts: 6

Rep: Reputation: 1
Thanks rmallins for the excellent post.

Can I suggest using sox instead of mplayer as it will allow you to re-sample and re-encode in one operation.

Code:
sox audio_book_disk_1.mp3 -t wav -r 16000 - | speexenc - audio_book_disk_1_16kHz.spx
The sox flags are "-t wav" so it knows to output in wav format and "-r 16000" which is the actual re-sample.

The use of the dash "-" tells sox to send the output to standard out and tells speexenc to read from standard in.
 
  


Reply

Tags
audio, mp3, wav



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GPG - encode file while manipulating output file name itmozart Linux - Newbie 2 10-03-2009 12:28 PM
encode text file anhtt Solaris / OpenSolaris 8 04-03-2008 12:03 AM
Looking for codecs to encode non-linux file formats ON a linux machine SPGWhistler Linux - Software 5 02-28-2007 11:38 PM
Running Game, but no Speex :/ pmaynard Fedora 5 02-20-2006 08:31 AM
Script to copy AND encode Audio CD squabsy Linux - Software 3 09-20-2005 03:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration