The basics of improvisation on the ocarina
If you watch someone who is experienced with improvisation it could appear that they are just pulling a melody from thin air, but that's not how it works.
Learning how to improvise music on the ocarina is a lot like speaking a language. When you speak in your native language, you don't assemble words a letter at a time - rather you think in concepts, and sentences 'just happen'.
Learning how to improvise means learning the conceptual 'words' of melody and rhythm, and the skills to assemble those into a 'musical conversation'. Like any skill, its essential to start with the basics, and don't expect to become awesome straight away.
The pentatonic scale
The pentatonic scale is special as it allows you to play any note over any chord and the result won't sound bad. You can hear it below.
You need to practice this and repeat it until you don't need to think about it any more.
So you have a scale, but what can you do with it?
If you were to just randomly choose notes from the scale, it would sound really dull and unstructured. So instead, improvisers work around melodic figures - short patterns of a few notes.
We will be starting with just one figure:
The key thing with forming melodic figures is to choose notes that are relatively close together, and align them with the beat of the melody.
Building a melody
Once you have a figure, you can start improvising by playing that figure multiple times, and moving it around within the scale.
But using just one melody fragment, it can sound a bit dull right? So you can add a second one to add some variation. Something that can work well is contrary motion. If your main figure mostly ascends, try introducing a figure that descends.
And introducing it in a few places results in this:
The thing here is to not go excessively into introducing variations. Add a small number of variations as a basis, and hold them. See how long you can hold them before it starts to sound boring. That's about when you'd want to change the figures.
Ideas for figures can be gained from listening to people playing. Listen to someone improvising, and try to identify the common patterns that they are using. But also do the same for other music, you don't need to learn figures just from improvisation.
Improvising with a backing track can be a lot of fun. Finding a chordal a jam track is easy. If you are playing a C ocarina, just look up 'C jam track' on youtube and you will find lots of options. Note that for this to sound right, you absolutely have to learn to play in tune.