def initWithRequestSpeechHook(self, requestSpeechHook=None): self = super(NSSpeechSynthesizerDriver, self).init() if self: self._speechGenerator = None self._currentLabel = 'text' self._currentStream = 0 self._isFirstSpeech = True self._delegator = { 'onStart': [], 'onWord': [], 'onEndStream': [], 'onFinish': [] } self._grabbingSpeech = False self._signalsEnabled = True self._requestSpeechHook = requestSpeechHook self._tts = NSSpeechSynthesizer.alloc().initWithVoice_(None) self._tts.setDelegate_(self) self._tts.setVolume_(1.0) self._tts.setRate_(200) self._pauseLength = 0 self._done = True return self
def awakeFromNib(self): NSLog('awakeFromNib') self.voice = NSSpeechSynthesizer.defaultVoice() self.speech = NSSpeechSynthesizer.alloc().initWithVoice_(self.voice) self.voiceFullnames = NSSpeechSynthesizer.availableVoices() self.voices = [ name[name.rindex('.') + 1:] for name in self.voiceFullnames ]
def initWithProxy(self, proxy): self = super(NSSpeechDriver, self).init() if self: self._proxy = proxy self._tts = NSSpeechSynthesizer.alloc().initWithVoice_(None) self._tts.setDelegate_(self) # default rate self._tts.setRate_(200) self._completed = True return self
def initWithProxy(self, proxy): self = super(NSSpeechDriver, self).init() if self: self._proxy = proxy self._tts = NSSpeechSynthesizer.alloc().initWithVoice_(None) self._tts.setDelegate_(self) # default rate self._tts.setRate_(200) self._completed = True return self
def __init__(self): if platform.system() != "Darwin": raise RuntimeError("NSSpeechSynthesizer wrapper only available on Mac OS X") try: from AppKit import NSSpeechSynthesizer except ImportError: try: from Cocoa import NSSpeechSynthesizer except: raise ImportError("NSSpeechSynthesizer not properly installed on this computer") self.tts = NSSpeechSynthesizer.alloc().initWithVoice_(None)
def wsay(afile): #https://stackoverflow.com/questions/12758591/python-text-to-speech-in-macintosh #NSSpeechSynthesizer.availableVoices() speechSynthesizer = NSSpeechSynthesizer.alloc().init() speechSynthesizer.setVoice_( 'com.apple.speech.synthesis.voice.karen') x = open(afile, "r") txt = x.read() txt = txt.split("====") txt = txt[0] x.close() speechSynthesizer.startSpeakingString_(txt)
def speak(text, voice, output_file): if not voice in VALID_VOICES: raise ValueError("Invalid voice, should be one of {0}".format(VOICES)) ve = NSSpeechSynthesizer.alloc().init() ve.setVoice_('com.apple.speech.synthesis.voice.' + voice) ve.startSpeakingString_toURL_(text, NSURL.fileURLWithPath_(output_file)) while ve.isSpeaking(): pass return find_aiff_length_ms(output_file)
def speak(text, voice, output_file): if not voice in VALID_VOICES: raise ValueError("Invalid voice, should be one of {0}".format(VOICES)) ve = NSSpeechSynthesizer.alloc().init() ve.setVoice_('com.apple.speech.synthesis.voice.' + voice) ve.startSpeakingString_toURL_(text, NSURL.fileURLWithPath_(output_file)) while ve.isSpeaking(): pass return find_aiff_length_ms(output_file)
def say(text, voice_id=default_voice): ''' | Read text in user-selected voice, or use default voice if no voice argument is passed in. | It is possible to enter a voice name anywhere in the text entry window using the format: <VoiceName> ''' text_read = text ve = NSSpeechSynthesizer.alloc().init() ve.setVoice_(voice_id) if '>' in text and text[text.index('<') + 1:text.index('>')] in voices: ve.setVoice_(voices[text[text.index('<') + 1:text.index('>')]]) text_read = text[0:text.index('<')] + text[text.index('>') + 1:] ve.startSpeakingString_(text_read.lower()) return
def __init__(self): self.thread = None self.shutdown = False system = platform.system() if system == 'Darwin': try: from AppKit import NSSpeechSynthesizer voice = 'Vicki' base = 'com.apple.speech.synthesis.voice' self.voice = base + '.' + voice self.speech = NSSpeechSynthesizer.alloc().initWithVoice_(self.voice) # sierra? if not self.speech: self.speech = NSSpeechSynthesizer.alloc().initWithVoice_(base + '.' + 'Victoria') self.say = self.__say_mac except ImportError: # osx lacks appkit support for python3 (sigh) self.say = self.__say_dummy elif system == 'Linux': self.say = self.__say_linux else: raise NotImplementedError('Platform not supported') self.queue = Queue()
def playEvent(self, event, notificationData=None): if event not in self._events: return if notificationData is None: notificationData = {} data = self._events[event] text = data.get("speak") if text: text = populateText(text, notificationData) synthesizer = NSSpeechSynthesizer.alloc().initWithVoice_(None) synthesizer.startSpeakingString_(text) sound = data.get("sound") if sound != "no sound" and sound in self._sounds: sound = self._sounds[sound] sound.play()
def tts_NS(word): ## Initialise voice synthesizer # synth = [[NSSpeechSynthesizer alloc] initWithVoice:nil]; synth = NSSpeechSynthesizer.alloc().initWithVoice_(None) ## Set voice values synth.setVoice_(VOICE) synth.setVolume_(VOLUME) synth.setRate_(RATE) ## Create NSURL path filepath = "../Audio/" + str(len(WORDS)) + "_" + word + "_NS.aiff" url = NSURL.fileURLWithPath_(filepath) ## Save sythesized word synth.startSpeakingString_toURL_(word, url)
def tts_NS(word): ## Initialise voice synthesizer # synth = [[NSSpeechSynthesizer alloc] initWithVoice:nil]; synth = NSSpeechSynthesizer.alloc().initWithVoice_(None) ## Set voice values synth.setVoice_(VOICE) synth.setVolume_(VOLUME) synth.setRate_(RATE) ## Create NSURL path filepath = "../Audio/" + str(len(WORDS)) + "_" + word + "_NS.aiff" url = NSURL.fileURLWithPath_(filepath) ## Save sythesized word synth.startSpeakingString_toURL_(word, url)
def init_synth(voice=None): if not is_appkit_available: print "speech synthesizer is not available." return None def init_(voiceIdentifier): return NSSpeechSynthesizer.alloc().initWithVoice_(voiceIdentifier) global synth if voice is None: # no voiceIdentifier is specified synth = NSSpeechSynthesizer.alloc().init() elif voice[:4] == 'com.apple.speech.synthesis.voice.': # an exact voiceIdentifier is specified synth = init_(voice) else: voice1 = 'com.apple.speech.synthesis.voice.' + voice voice2 = 'com.apple.speech.synthesis.voice.' + voice.lower() + '.premium' synth = init_(voice1) or init_(voice2)
from AppKit import NSSpeechSynthesizer speechSynthesizer = NSSpeechSynthesizer.alloc().initWithVoice_( "com.apple.speech.synthesis.voice.Bruce") print "hello" speechSynthesizer.startSpeakingString_('Hi! Nice to meet you!')
def init_(voiceIdentifier): return NSSpeechSynthesizer.alloc().initWithVoice_(voiceIdentifier)
def __init__(self, message): self.synth = NSSpeechSynthesizer.alloc().initWithVoice_(None) self.synth.startSpeakingString_(message)
try: # will run if on OSX from AppKit import NSSpeechSynthesizer ve = NSSpeechSynthesizer.alloc().init() ve.setVoice_('com.apple.speech.synthesis.voice.kate.premium') os_version = 1 except Exception, e: # run if on linux print e from os import system os_version = 2 import time import subprocess def talking(text): # talking creates the estimated time to speak and then creates speech talk_time = len(text) / 9 # runs if OSX if os_version == 1: while ve.isSpeaking: ve.startSpeakingString_(text) time.sleep(talk_time) break # runs if Linux elif os_version == 2: system('pico2wave -w /tmp/ttspeech.wav \"a ' + text + '\"') speak = subprocess.call(['aplay', '/tmp/ttspeech.wav'])
""" This module behaves like pyTTS. It runs on Mac OS X with NSSpeechSynthesizer. The only behavior provided is the behavior that tts.py needs. """ from AppKit import NSSpeechSynthesizer # @UnresolvedImport # not used; provided for compatibility tts_async = 0 tts_purge_before_speak = 0 _engine = NSSpeechSynthesizer.alloc().init() class TTS(object): def __init__(self): pass def IsSpeaking(self): return _engine.isSpeaking() def Speak(self, text, *args): _engine.startSpeakingString_(text) def Stop(self): _engine.stopSpeaking()
def say(txt): voice = NSSpeechSynthesizer.defaultVoice() speech = NSSpeechSynthesizer.alloc().initWithVoice_(voice) speech.startSpeakingString_(txt)
def awakeFromNib(self): NSLog('awakeFromNib') self.voice = NSSpeechSynthesizer.defaultVoice() self.speech = NSSpeechSynthesizer.alloc().initWithVoice_(self.voice) self.voiceFullnames = NSSpeechSynthesizer.availableVoices() self.voices = [name[name.rindex('.') + 1:] for name in self.voiceFullnames]
# =============================================================================== # ============= enthought library imports ======================= from __future__ import absolute_import import time from pyface.timer.timer import Timer from traits.api import HasTraits, Button, Int, Bool, Property from traitsui.api import Handler, View, Item, UItem, VGroup, HGroup, spring, Spring, ButtonEditor from pychron.core.ui.lcd_editor import LCDEditor try: from AppKit import NSSpeechSynthesizer SPEECHSYNTH = NSSpeechSynthesizer.alloc().initWithVoice_("com.apple.speech.synthesis.voice.Vicki") SPEECHSYNTH.setRate_(275) except ImportError: SPEECHSYNTH = None class StopWatchHandler(Handler): def closed(self, info, isok): info.object.destroy() class StopWatch(HasTraits): start_stop_button = Button reset_button = Button('Reset') current_time = Int call_interval = Int(5)
from AppKit import NSSpeechSynthesizer import Cocoa TEXT = "Good-bye! Nice to know you." # TTS variables RATE = 170 # Value in words per minute; human 180-220 VOLUME = 0.5 # Floating point value in the range of 0.0 to 1.0, inclusive. VOICE = 'com.apple.speech.synthesis.voice.Agnes' # String identifier of the active voice. ### RUN showcase_voices.py TO SEE ALL AVAILABLE VOICES IN YOUR SYSTEM ### if __name__ == '__main__': ## Initialise voice synthesizer # synth = [[NSSpeechSynthesizer alloc] initWithVoice:nil]; synth = NSSpeechSynthesizer.alloc().initWithVoice_(None) ## Fetch all system voices available voices = NSSpeechSynthesizer.availableVoices() ## Set voice values synth.setVolume_(VOLUME) synth.setRate_(RATE) # synth.setPitch_(PITCH) ## Print out all system voices available for voice in voices: print voice for voice in voices: # synth = NSSpeechSynthesizer.alloc().initWithVoice_(voice)
level = 2 score = 0 font_size = 25 run = True dict_words = {} showords = {} choosed_wd = {} cur_word = '' result = '' q = Queue() if "Darwin" in platform.system(): dir = os.path.sep.join(sys.argv[0].split(os.path.sep)[:-1]) font_file = "/System/Library/Fonts/PingFang.ttc" ''' 引入发音引擎''' from AppKit import NSSpeechSynthesizer speaker = NSSpeechSynthesizer.alloc().init() from_voice = "com.apple.speech.synthesis.voice.Princess" speaker.setVoice_(from_voice) else: dir = os.path.dirname(__file__) font_file = r"C:\windows\Fonts\msyh.ttc" import win32com.client as wincl speaker = wincl.Dispatch("SAPI.SpVoice") ''' 引入google在线翻译引擎''' from googletrans import Translator translator= Translator() def translat(word,q): res = translator.translate(word,src='en', dest='zh-cn').text q.put_nowait(res)
# =============================================================================== # ============= enthought library imports ======================= from __future__ import absolute_import import time from pyface.timer.timer import Timer from traits.api import HasTraits, Button, Int, Bool, Property from traitsui.api import Handler, View, Item, UItem, VGroup, HGroup, spring, Spring, ButtonEditor from pychron.core.ui.lcd_editor import LCDEditor try: from AppKit import NSSpeechSynthesizer SPEECHSYNTH = NSSpeechSynthesizer.alloc().initWithVoice_( "com.apple.speech.synthesis.voice.Vicki") SPEECHSYNTH.setRate_(275) except ImportError: SPEECHSYNTH = None class StopWatchHandler(Handler): def closed(self, info, isok): info.object.destroy() class StopWatch(HasTraits): start_stop_button = Button reset_button = Button('Reset') current_time = Int call_interval = Int(5)