From 9203e592f9b700178a7610e418faa41b7323bb8d Mon Sep 17 00:00:00 2001 From: "dtseng@chromium.org" Date: Fri, 27 Aug 2010 18:07:40 +0000 Subject: Reland 3149027. Review URL: http://codereview.chromium.org/3236004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57701 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/extensions/extension_tts_api_mac.mm | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 chrome/browser/extensions/extension_tts_api_mac.mm (limited to 'chrome/browser/extensions/extension_tts_api_mac.mm') diff --git a/chrome/browser/extensions/extension_tts_api_mac.mm b/chrome/browser/extensions/extension_tts_api_mac.mm new file mode 100644 index 0000000..98e49e3 --- /dev/null +++ b/chrome/browser/extensions/extension_tts_api_mac.mm @@ -0,0 +1,39 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "extension_tts_api.h" + +#include + +#include "base/values.h" +#include "chrome/browser/extensions/extension_function.h" + +#import + +static NSSpeechSynthesizer* speech_synthesizer_; + +void InitializeSpeechSynthesizer() { + if (!speech_synthesizer_) + speech_synthesizer_ = [[NSSpeechSynthesizer alloc] init]; +} + +bool ExtensionTtsSpeakFunction::RunImpl() { + InitializeSpeechSynthesizer(); + std::string utterance; + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &utterance)); + return + [speech_synthesizer_ startSpeakingString: + [NSString stringWithUTF8String: utterance.c_str()]]; +} + +bool ExtensionTtsStopSpeakingFunction::RunImpl() { + InitializeSpeechSynthesizer(); + [speech_synthesizer_ stopSpeaking]; + return true; +} + +bool ExtensionTtsIsSpeakingFunction::RunImpl() { + InitializeSpeechSynthesizer(); + return [speech_synthesizer_ isSpeaking]; +} -- cgit v1.1