ibm-cloudgstreameribm-watsongstreamer-1.0watson-text-to-speech

How to stream audio in Gstreamer (Python)


I am making a python application that takes text converts it into audio using ibm cloud Watson TTS, then return an audio using

content = watson_tts.synthesize(text, voice), accept=format).get_result().content

then I want to take this content and stream using Gstreamer, without saving it to a file. I know how to play files from uri using this:

player = Gst.ElementFactory.make("playbin", "player")
player.set_property("uri", uri)
player.set_state(Gst.State.PLAYING)

but that's not what I want, what I want is being able to stream the audio directly without downloading


Solution

  • After executing

    content = watson_tts.synthesize(text, voice), accept=format).get_result()
    

    synthesized audio is already "downloaded" from IBM's service so instead of "what I want is being able to stream the audio directly without downloading" I suppose it's better to say "... without saving to a file".

    Anyways... to "programmatically" feed gstreamer's pipeline with (audio) bytes from Python's content object, you can utilize appsrc element.

    For example, the pipeline can be implemented something like this enter image description here

    and it will produce MPEG Transport Stream with aac encoded audio streamed via UDP.