ENDINGS can be bittersweet. No-one knows this better than Ann Cleeves. The author has faced the grief of saying goodbye to two important men in her life this past year: one a fictional character beloved by millions, the other a flesh and blood soulmate beloved by her.

It’s August when we meet and the intoxicating carnival of the Edinburgh International Book Festival is in full swing as we find a quiet corner away from the main hubbub in Charlotte Square.

We’re here to talk about her latest novel Wild Fire: the final instalment in the best-selling Shetland series featuring brooding detective inspector Jimmy Perez. When Cleeves published the first book Raven Black in 2006, she never envisaged the many doors it would open.

It has since evolved into eight books (and a novella) which have been adapted into a hugely successful BBC television drama, Shetland, starring Douglas Henshall and are credited with sparking an influx of tourism to the archipelago of islands where her mesmerising crime stories are set.

Cleeves, 63, has done a farewell book tour across Shetland in recent days, visiting libraries and the town hall in Lerwick. She is sanguine when asked what it was like writing Wild Fire and winding up the popular series.

“I knew it would be the last and that I was ready to finish it,” she says. “It wasn’t so sad, but there was a lot of pressure because I didn’t want it to be a weak last book. There was that pressure to get it right and to tie together what I felt about Shetland.”

In many ways, she says, it has felt like coming full circle. “It is almost taking it back to the beginning because it is about what it is to be an outsider again which is what the first book was about too.”

It has been a journey packed with as many twists as any crime fiction story. “Raven Black was going to be a standalone novel,” she recalls. “Then I thought I would kill Jimmy off in the fourth book because that was the end of the first quartet, but I killed someone else off instead.

“I decided that I would carry on and write another four. So, I knew that it was coming. There wasn’t enough material and I wasn’t sufficiently passionate about it to write four more books. I wanted to end with the eighth.”

Besides, there were other practical reasons for bringing the series to a close. “There are only 23,000 people living in Shetland and I have killed a fair few off,” she laughs. “The TV series has killed even more.”

Her own Shetland story began in 1975. Cleeves, then 20, had dropped out of university when a chance conversation in a pub led to a job as an assistant cook at the Fair Isle Bird Observatory. Never mind, she jokes, that her ornithology knowledge and culinary skills were somewhat lacking.

She recounts turning up on Shetland’s mainland to catch the boat to Fair Isle. There was no cafe or waiting room at the pier, merely a telephone box where Cleeves sheltered from the wind. “I waited and waited. Finally, the postie came by and told me: ‘Oh no, the boat won’t come today, the weather is too bad.’

“So, I had to find a B&B. I was there for two nights. The woman who ran the B&B was brilliant and could see I was skint. I paid for bed and breakfast – but she gave me lunch and dinner as well.”

When Cleeves eventually arrived on Fair Isle, she settled into a routine of cooking, cleaning toilets and chambermaid work. “One of my jobs was to cycle down the island waving a flag to tell everyone if a rare bird had been spotted,” she says.

“In the spring when they were rounding up the hill sheep for clipping, all the bird observatory staff would be out helping. I got to clip the sheep too – I wasn’t brilliant, but I gave it a go.”

It was on Fair Isle that Cleeves met her husband Tim, a visiting ornithologist who had come to observe the autumn migration. He proposed a year later as they sat in a hay trailer on the way back to a friend’s croft after a day helping in the fields.

The couple celebrated their 40th wedding anniversary in February last year. But only months later, Tim took ill and was diagnosed with a heart condition. He died in hospital in December, aged 67.

Cleeves was in the final stages of working on Wild Fire when he passed away. “Some people are a bit snobby about books that are escapes,” she says. “But I think that is a perfectly valid way to escape into a fictitious world. I did that writing.”

While the bereavement is still raw and recent – Tim died only nine months ago – Cleeves clearly draws strength and joy from sharing anecdotes about the couple’s many adventures.

As newly-weds they lived on Hilbre, a tiny tidal island in the Dee Estuary where Tim had a job as warden. “We were the only people living there,” she says. “It wasn’t that isolated because it was only a mile-and-a-half off shore, but it was a weird existence.

“In the winter it was lovely because no one came apart from other bird watchers. Then in the summer, you would get this influx of people as soon as it was a nice day.”

Cleeves wrote her debut novel, A Bird In The Hand, while living on Hilbre. Set in the world of the twitchers, it was published in 1986. Ornithology would again be a muse when on a flying visit to Fair Isle in 2004 – to catch a glimpse of a rare bird, naturally – she had the idea for Raven Black.

Is she a bird lover herself? “Not at all,” says Cleeves cheerfully before reeling off a list that would make any twitcher envious. “There were a couple of things I had seen that Tim hadn’t. My Bimaculated lark was one of them and I don’t think he ever saw an American kestrel either.”

Before turning her hand to writing, Cleeves did an array of jobs, including with the social work department in London’s King’s Cross, where she cared for children with behavioural difficulties. She later trained as a probation officer and did outreach work for public libraries.

When based on Hilbre, there was a stint as an auxiliary coastguard. “We had to do exercises with maps and compasses,” she says. “It was like maths. I was awful. Tim said it was the only time he was ever the boss. He just despaired because I was so hopeless.”

The eldest of two daughters, Cleeves grew up in small villages across Herefordshire until the family moved to Barnstaple in North Devon when she was 11. Her father was a primary school headteacher and her mother worked as a secretary and shop assistant.

Cleeves alludes to a slightly awkward childhood. “It is quite hard to make friends if your dad is the school teacher. I was much more an observer than a participant. I was always watching and curious about what other people were doing, but slightly solitary. I spent a lot of my time reading.”

What was it like being taught by her father? “It was just what I knew,” she shrugs. “But it was a bit odd because at home he was ‘dad’ and in school he was ‘Mr Richardson’. I don’t think it was ever said that I should call him Mr Richardson, but it would have been strange to call him dad at school.”

The seeds for becoming a writer were sown at an early age. “I was always a storyteller,” says Cleeves. “Even before I could read and write, I can remember having a running narrative in my head in the third person describing what I was doing. I was always outside looking in.”

She has published 32 books to date. They have inspired two long-running TV dramas. Vera, starring Brenda Blethyn as the eponymous detective, was famously picked up by ITV after a scriptwriter found a second-hand copy of The Crow Trap in a charity shop. It is now in its ninth series.

In a similar twist of fate, drama producer Elaine Collins – then working for ITV Studios – optioned the Shetland books after falling in love with them. Screenwriter David Kane, whose credits include The Field Of Blood, Taggart and Rebus, adapted the novel Red Bones for the debut BBC series in 2013.

Three two-part dramas based on Raven Black, Dead Water and Blue Lightning followed. Series three and four were written exclusively for television, as was the upcoming fifth series which is currently being filmed on location in Glasgow and Shetland.

It means that Perez – as portrayed by Henshall – will live on within the small screen. I’m curious, though, how Cleeves feels bidding farewell to her own Perez? “I have said goodbye to Jimmy, but I will miss him,” she says.

There was poignant timing about her decision to finish writing the book series. Did it feel like there were parallels with her own life? “It did,” she says. “Because I met Tim in Shetland and I was finishing the Shetland book at the time he died, it did feel that it was right somehow.

“That it was the right time to be finishing the books. It would have been hard if there was another book to come. That would have been really tricky.”

Her calling card is getting beneath the skin of isolated communities, places with deeply ingrained values where everyone knows their neighbours, leaves their doors unlocked and outsiders are viewed warily.

Wild Fire continues that theme. “It is about how what happened in the generation before can play out in present times. The title had to have fire in it because the previous three book titles were all elements. Wild Fire made me think of gossip, rumour and how destructive that can be.

“Some of the nastiest things I have heard people say have been in the school playground while waiting to pick up kids. Mums who are lacking in confidence can be really bitchy about other people – a sort of gang mentality that is horrible. I wanted to explore that.”

Fans will be desperate to find out if Cleeves has given her leading man a happy or tragic ending (no spoilers here). The book is a gripping whodunnit, yet equally feels like a love letter to the islands. “I do love Shetland so much. I’ll still go back and will probably write short stories set there.”

Cleeves has a new series in the pipeline and has already started writing. “It is set in North Devon,” she says. “Again, it is a community on the edge. It has a big, faded seaside town that attracts transients who work in the big hotels during the summer.

“There are the Hooray Henrys, posh public-school kids who come down to surf. It is quite arty and a few ageing hippies have washed up there and stayed. I’m quite interested in exploring that.”

She confirms it will centre on a police figure yet is tight-lipped about the specifics. Cleeves is enjoying immersing herself in the project. “It feels quite easy to write at the moment because it is something new and that I am excited about.”

Is a third TV adaptation in her future? Cleeves hoots with laughter. “That would be a bit greedy. There is so much good crime fiction out there and other people deserve a chance.”

While Perez has had his last hurrah, fans of DI Vera Stanhope can breathe a sigh of relief. Cleeves reckons that the book series, set in the north-east of England, has plenty of life yet.

“I’m going to write more Vera. It is a much wider palette with the city, post-industrial [landscape] and former pit villages, beautiful coast and hills. There is lots going on.”

Home these days is Northumberland where Cleeves lives close to her two daughters and six grandchildren. She was recently named as a patron of Tyneside and Northumberland Mind, a mental health charity which has personal meaning because her late husband Tim was bipolar.

Cleeves has commissioned a piece of fiddle music to mark the end of the Shetland books. The composition, A Tune For Jimmy Perez, was written by Shetlander and musician Cathy Geldard.

“I asked if she could find a traditional Fair Isle tune to start it off,” says Cleeves. “It is a journey with some slow bits, a reel and a jig – very much in the format of Shetland music. It begins using the rhythm of a traditional Fair Isle grace. That is very special. It is a lovely piece of music.”

How did it feel hearing that for the first time? “Amazing,” she smiles. “I said to Cathy: ‘Tim has just died, I think it is a tune for Tim as well.’ So, I will have that to keep. Although it is a tune for Jimmy Perez, it is also a tune for Tim.”

Her goal moving forward is simple. “I just want to keep writing,” says Cleeves. “I love it. I get up in the morning and sit at my kitchen table in my pyjamas making stuff up. I am being all these people. I’m in their heads seeing the world through their eyes. What could be better than that?”

She shakes her head when asked about regrets. “I’ve been lucky. It has been a good life. There have been some dark times when Tim was ill. I had breast cancer when I was in my early 30s and missed out on taking my youngest daughter to her first day at school.

“It has not been rosy all the way, but I have been very lucky to have a happy marriage and lovely family. There are still stresses in life, but overall I have had a pretty good time.”

Wild Fire by Ann Cleeves is published by Macmillan, priced £16.99. The author is at Bloody Scotland in Stirling on September 23. Visit bloodyscotland.com