Speaking at the launch of the festival, Barley described the return of the city's festivals this month as "a defiant moment" against "forces that want to silent us."
Speaking in the wake of the stabbing of Sir Salman on stage at an event in New York state and a subsequent threat made against Edinburgh-based author JK Rowling, Mr Barley stressed the importance of "listening to each other".
He added that the book festival was under-pinned by a principle that "you don't get discourse without disagreement."
The book festival was launched hours after Sir Salman, a regular visitor to the event, was left with severe life-changing injuries following the one-stage attack.
His son Zafar posted an update on Sunday afternoon stating that although he remained in a critical condition he had been able to say a few words and that his “usual feisty and defiant sense of humour remains intact.”
Earlier, the author's agent Andrew Wylie said his "road to recovery has begun", adding: "It will be long; the injuries are severe, but his condition is headed in the right direction.”
The 75-year-old novelist faced years of death threats for his novel The Satanic Verses, which some Muslims see as blasphemous. He was forced into hiding for nearly 10 years after it was published in 1988.
A 24-year-old man has pleaded not guilt to attempted murder after being charged over Friday’s attack.
Meanwhile a police investigation is underway over an "online threat" made to JK Rowling after she tweeted her reaction to the stabbing of Sir Salman. She had shared screenshots of a message from a user who had written "don't worry you are next" in response to her tweet.
Edinburgh is staging its first full-scale season of summer festivals since 2019 in the 75th anniversary year of their formation, in the aftermath of the Second World War.
Speaking at the launch event, Mr Barley encouraged people to celebrate the return of Edinburgh’s festivals in the face of the impact of Covid, the cost of living crisis and the threats to writers.
Mr Barley said: "Of all the complicated emotions that I feel as I stand in front of you there's only one that I really want to talk abou, which is joy.
"Joy that we can meet back here together and joy, above all, that this festival as it opens marks the completion of the 2022 festivals in this city - the art festival, the international festival, the Fringe, the Tattoo, the film festival and now the book festival. Edinburgh's festival city is once again open and I'm overjoyed about that.
"We must feel joy. The last few years have been really tough for all of our festivals. But now we're back. It's been painful for us.
"But I've got to pay tribute to the incredible teams here at the book festival and across the festival city who have been through terrible troubles to get the festival alive and we are back.
"Maybe at times it feels hard to celebrate. It feels strange to celebrate and to have a festive spirit at a time when we've faced so many challenges. Is it fair and correct to have a festival against that backdrop of so much tragedy of COVID?
"Is it correct and appropriate with all the struggles of the cost of living crisis and with the threats to life from violence against the likes of Salman Rushdie?
“Well, yes, because in my view, I have come to think of a festival as a form of defiance.
"A festival is the thing we have left to spite against the forces that would stop us from being festive because they want to silence us. We will not be silenced across the city. We will have a festival and we will celebrate. It's what we can do to resist. This is our defiant moment.”
Mr Barley said he had drawn inspiration from the words of Ali Smith, one of the first authors to speak at this year’s book festival.
He added: “Ali Smith talked about the meaning of words and the importance of words. She used the word meandering. And it felt relevant because meandering is something that I think many of us do around the festival city.
“We go to events with people we've heard of and we wander into small events with people we've never heard of. Meandering around is part of Edinburgh’s festival experience.
"Ali talked about the word meandering and she says its etymology comes from taking me outside myself and othering myself - that's what meandering means.
“If you think about it, festivals are about differences. You might go to a comedy show and love it, and I might find it despicable. I might go to a piece of experimental theatre which I love, and you might think it's boring.
"Difference is part of the festival experience. And if you've been talking to friends who've seen things already this week, you'll know that festivals are all about talking to each other about what we liked and what we didn't like.
“That understanding of difference, that diversity of experience and that listening to each other is part of the essential joy of the festival experience - diversity, listening to each other and discourse. You don't get discourse without disagreement. And that's what the book festival thrives on.
“It's not always easy. We won't always find agreement with each other and sometimes we might even feel hurt or surprised by other people's views.
"But it's essential that we have those conversations right here. And that is the defiant spirit of the book festival. And that, in summary, is why I think this is a moment of joy and a moment of celebration.”