[Speex-dev] Determining length of speex file speech
Conrad Parker
conrad at metadecks.org
Tue May 16 16:52:08 PDT 2006
On Tue, May 16, 2006 at 03:29:47PM +0200, Björn Thalheim wrote:
>
> I would like to run a script over a speex file which determines, how
> long the speech contained in the speex file is.
> So I run through the ogg file, skip the first two ogg _pages_ (speex
> header and comment header, both contain IMHO only 1 ogg _packet_), and
> then count in any ogg page the number of the ogg _frames_ (which, unless
> I used -nframes while encoding, which I did not), and multiply this with
> .02 (20 milliseconds).
> I did this by hand, for example on the file I send yesterday when asking
> about the noise, so the output of the program is:
>
> $ readspx spfe49_1-small.spx
> speex header
> Version:1.1.12
> rate:44100
> mode:2
> mode_bitstream_version:4
> nb_channels:2
> bitrate:-1
> frame_size:640
> vbr:0
> frames_per_packet:1
> extra_headers:0
> Page #2: 1 packets.
> Page #3: 45 packets.
> Page #4: 45 packets.
> Page #5: 45 packets.
> Page #6: 45 packets.
> Page #7: 45 packets.
> Page #8: 45 packets.
> Pages: 8
> Packets: 272
>
> Calculating things per hand here 6*45 speex frames, so the speech length
> should be 5.4 seconds. Unfortunately this is overestimated:
Hi Björn,
The number of pages is irrelevent. Pages are just the container that
stores packets, and the number of packets in each page could vary. You
only need to keep track of the number of packets in the file. Then:
encoded_speex_frames = (frames_per_packet * Packets)
= 1 * 272
= 272
audio_samples = encoded_speex_frames * frame_size
= 272 * 640
= 174080
duration = audio_samples / rate
= 174080 / 44100
= 3.947
cheers,
Conrad.
More information about the Speex-dev
mailing list