According to legends told by people in Misthallery, long ago, a group of bandits attacked a small village (hinted to be also Misthallery). In the middle of the chaos, there was a young, terrified girl who decided to play her flute to take her mind off the madness. When the music played, a giant specter appeared in the sky above her. The girl begged the specter to destroy the bandits, and it did so, and then disappeared.
This story is retold by Jean Descole at the beginning of Last Specter.
The flute was actually real, and was found in a rubbish pile by Scraps, who gave it to Crow, the leader of the Black Ravens, to sell. It was sold to Evan Barde, the squire of Misthallery, as he was the highest bidder at the auction for it.
Evan then gave the ocarina to his daughter Arianna, who used it to train and soothe her friend, the lake creature Loosha. Six months after Evan bought the ocarina, he died in an accident after falling off a cliff, and Arianna inherited the ocarina, continuing to playing it for Loosha with her brother Tony.
In the events of Last Specter, the scientist Jean Descole uses the mining machines used in the search for the Golden Garden to terrorize Misthallery at night, attacking buildings. Loosha, being able to move around on land, tried to stop the machine, so Arianna would play the ocarina into the town's old water pipe network so it would echo all around.
As Arianna owns the Specter's Flute, the Chief of Police Levin Jakes, bribed by Descole, arrests her and accuses Loosha of being the specter. However, Professor Layton uncovers the mystery and reveals the true identity of the monster destroying the village.
Even though the Specter's Flute is said to be a flute, it is in fact an ocarina, an instrument that's older than the flute itself and can come in various forms, famous for its appearance in The Legend of Zelda: Ocarina of Time.