The study was led by Laura V Cuaya at Eotvos Lorand University in Budapest, who moved to the city from Mexico a few years ago, bringing her dog Kun-kun with her.
"I wondered whether Kun-kun noticed that people in Budapest spoke a different language, Hungarian," she said.
"(In the research) we found for the first time that a non-human brain can distinguish (between) languages."
In their lives with humans, dogs pick up on the auditory patterns of the language they are exposed to, said Raul Hernandez-Perez, co-author of the study.
During the experiment, Kun-kun and others were trained to lie down motionless in a brain scanner for several minutes.
All the dogs had heard only one of the two languages -- either Hungarian or Spanish -- from their owners before, allowing researchers to compare how their brain reacted to a highly familiar language and to a completely unfamiliar one.
The dogs listened to excerpts from the story in Spanish and Hungarian and also scrambled versions of these excerpts to test if they could detect speech and non-speech.
When comparing brain responses, researchers found distinct activity patterns in dogs' primary auditory cortex of the brain, indicating that they can distinguish between speech and non-speech.
In their secondary auditory cortex which analyses complex sounds, dogs' brains produced different activity patterns when they heard a familiar language and an unfamiliar language. The older the dogs were, the better their brain distinguished between the two languages.