How did Percy Bysshe Shelley come to write ‘Ode to a Skylark’?

In 1839 Mary Shelley revealed that while staying with her husband near Livorno they heard a skylark: ‘It was on a beautiful summer’s evening while wandering among the lanes whose myrtle hedges were the bowers of the fire-flies, that we heard the carolling of the skylark’.

The start of the poem casts doubt on whether the bird is actually real, but P B Shelley continually references its flight, song, and other physical attributes, setting the scene for an exploration of the relationship between opposites, the attainable and the unattainable, the desire to comprehend the incomprehensible.