[FFmpeg-devel] [PATCH] flite audio source

Stefano Sabatini stefasab at gmail.com
Mon Jul 23 15:23:44 CEST 2012


On date Sunday 2012-05-20 16:24:33 +0200, Nicolas George encoded:
> Le duodi 2 prairial, an CCXX, Stefano Sabatini a écrit :
> > Yes, but not natively, check attachment, test with:
> > ffplay -f lavfi "flite=text='Finned Francis molds plenty eager pomegranates'"
> 
> Very nice idea.
> 
> Unfortunately, if depends on an external library, it can not used for tests.
> 
> (When I was young, I had games on Atari ST that could speak. That was ugly
> and expressionless, but it could be understood, and it was done with only
> three squarewave channels. Isn't there someone who knows how to do it
> still?)
> 

> Also, it would be nice to be able to produce voice on different channels,
> such as "[FL]front left [FR]front right [BL]back left [BR]back right": to
> test channel layout problems, this is very useful. And it is probably quite
> easy to implement.

What about:
$ ffplay -f lavfi "flite=text='Hello world':voice=slt[a1]; flite=text='Hello world':voice=kal[a2];[a1][a2]amerge,asplit[out1],showwaves"
?

> 
> > >From 16bf1143e860835b4b26c552bd2d86421c999a99 Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > Date: Sun, 21 Aug 2011 02:29:33 +0200
> > Subject: [PATCH] lavfi: add flite audio source
> > 
> > ---
> >  configure                |    4 +
> >  libavfilter/Makefile     |    1 +
> >  libavfilter/allfilters.c |    1 +
> >  libavfilter/asrc_flite.c |  179 ++++++++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 185 insertions(+), 0 deletions(-)
> >  create mode 100644 libavfilter/asrc_flite.c
[...]
> > +
> > +cst_voice *register_cmu_us_kal(void *ptr);
> 
> What is that?

The not very nice way flite has to register the voices. I don't know
if there is a better way though. I extended this in order to support
the (unfortunately) few voices that flite currently support.

> > +
> > +static int init(AVFilterContext *ctx, const char *args, void *opaque)
> > +{
> > +    FliteContext *flite = ctx->priv;
> > +    int err = 0;
> > +    cst_voice *voice;
> > +
> > +    flite->class = &flite_class;
> > +    av_opt_set_defaults(flite);
> > +
> > +    if ((err = (av_set_options_string(flite, args, "=", ":"))) < 0) {
> > +        av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
> > +        return err;
> > +    }
> 
> ... and we could have a class field in AVFilter to let lavfi do that.

unrelated ;-)

> > +
> > +    if ((err = flite_init())) {
> 
> Does this support being called several times?

flite_init() is currently an empty function, so it really doesn't
matter much. I added a static guard against multiple initializations.

> 
> > +        av_log(ctx, AV_LOG_ERROR, "Could not init flite");
> > +        return AVERROR(EINVAL);
> 
> Nit: AVERROR_UNKNOWN?

Fixed.

> > +    }
> > +
> > +    voice = register_cmu_us_kal(NULL);
> > +
> > +    if (flite->textfile) {
> > +        uint8_t *textbuf;
> > +        size_t textbuf_size;
> > +
> > +        if (flite->text) {
> > +            av_log(ctx, AV_LOG_ERROR,
> > +                   "Both text and text file provided. Please provide only one\n");
> > +            return AVERROR(EINVAL);
> > +        }
> > +        if ((err = av_file_map(flite->textfile, &textbuf, &textbuf_size, 0, ctx)) < 0) {
> 
> We can not use it with a pipe. Don't we have some kind of av_read_file?
> Apparently not. I can submit a patch for that.

Dunno, would that require the use of libavformat AVIO API?

[...]
> > +static int request_frame(AVFilterLink *outlink)
> > +{
> > +    AVFilterBufferRef *samplesref;
> > +    FliteContext *flite = outlink->src->priv;
> > +    int nb_samples = FFMIN(flite->wave_nb_samples, 512);
> 
> Is there a particular reason for 512?

No, changed into a configurable paramter.

[...]

Updated against latest API.

Todo: use streaming API which seems supported in flite 1.4.
-- 
FFmpeg = Fiendish and Fostering Minimal Prodigious Ermetic Gymnast
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-lavfi-add-flite-audio-source.patch
Type: text/x-diff
Size: 13312 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120723/932af3e3/attachment.bin>


More information about the ffmpeg-devel mailing list