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 getvoicenames(): """I am returning the names of the voices available on Mac OS X.""" voices = NSSpeechSynthesizer.availableVoices() voicenames = [] for voice in voices: voiceattr = NSSpeechSynthesizer.attributesForVoice_(voice) voicename = voiceattr['VoiceName'] if voicename not in voicenames: voicenames.append(voicename) return voicenames
def getProperty(self, name): if name == 'voices': return [self._toVoice(NSSpeechSynthesizer.attributesForVoice_(v)) for v in list(NSSpeechSynthesizer.availableVoices())] elif name == 'voice': return self._tts.voice() elif name == 'rate': return self._tts.rate() elif name == 'volume': return self._tts.volume() else: raise KeyError('unknown property %s' % name)
def getVoiceList(self): ''' Returns a list of voices using the following format: [description, keyOrId] The keyOrId is what you would use to set the voice later on. ''' voiceList = NSSpeechSynthesizer.availableVoices() myList = [] for v in voiceList: descr = v.split('.')[-1] myList.append((unicode(descr), unicode(v))) return myList
def getProperty(self, name): if name == 'voices': return [ self._toVoice(NSSpeechSynthesizer.attributesForVoice_(v)) for v in list(NSSpeechSynthesizer.availableVoices()) ] elif name == 'voice': return self._tts.voice() elif name == 'rate': return self._tts.rate() elif name == 'volume': return self._tts.volume() elif name == "pitch": print("Pitch adjustment not supported when using NSSS") else: raise KeyError('unknown property %s' % name)
def set(self, attribute, value): '''Sets the specified attribute to the given value Recognized attributes: rate, voice, volume''' attribute = attribute.lower() if attribute == "voice": if not isinstance(value, str): raise TypeError("voice must be of type \"string\"") elif value not in self.available_voices(): raise ValueError("%s is not an available voice" % (value)) else: lss = NSSpeechSynthesizer.availableVoices() for ii in lss: if ii.encode("ascii").split(".")[-1] == value: value = ii break vol = self.tts.volume() rate = self.tts.rate() self.tts.setVoice_(value) self.tts.setRate_(rate) self.tts.setVolume_(vol) elif attribute == 'rate': if not isinstance(value, (int, float)): raise TypeError( "volume must be either an integer or floating point number" ) elif not 50 <= value <= 600: raise ValueError("volume value must be in range 50--600") else: self.tts.setRate_(value) elif attribute == 'volume': if not isinstance(value, (int, float)): raise TypeError( "volume must be either an integer or floating point number" ) elif not 0 <= value <= 100: raise ValueError("volume value must be in range 0--100") else: self.tts.setVolume_(value * 0.01) else: raise ValueError("\"%s\" not a recognized attribute" % (attribute))
def set(self, attribute, value): '''Sets the specified attribute to the given value Recognized attributes: rate, voice, volume''' attribute = attribute.lower() if attribute == "voice": if not isinstance(value,str): raise TypeError("voice must be of type \"string\"") elif value not in self.available_voices(): raise ValueError("%s is not an available voice" % (value)) else: lss = NSSpeechSynthesizer.availableVoices() for ii in lss: if ii.encode("ascii").split(".")[-1] == value: value = ii break vol = self.tts.volume() rate = self.tts.rate() self.tts.setVoice_(value) self.tts.setRate_(rate) self.tts.setVolume_(vol) elif attribute == 'rate': if not isinstance(value,(int,float)): raise TypeError("volume must be either an integer or floating point number") elif not 50 <= value <= 600: raise ValueError("volume value must be in range 50--600") else: self.tts.setRate_(value) elif attribute == 'volume': if not isinstance(value,(int,float)): raise TypeError("volume must be either an integer or floating point number") elif not 0 <= value <= 100: raise ValueError("volume value must be in range 0--100") else: self.tts.setVolume_(value*0.01) else: raise ValueError("\"%s\" not a recognized attribute" % (attribute))
''' from AppKit import NSSpeechSynthesizer try: from Tkinter import * # 2.X except: from tkinter import * # 3.X # inits text = '' entry_str = '' entry_length = 0 default_voice = 'com.apple.speech.synthesis.voice.Alex' voices = { str(voice[33:]): str(voice) for voice in NSSpeechSynthesizer.availableVoices() } voices_lst = [item.lower() for item in voices.keys()] 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:]
def available_voices(self): '''Returns a list of voices available for use with NSSS''' voices = NSSpeechSynthesizer.availableVoices() voices = list(voices) voices = [x.encode("ascii").split(".")[-1] for x in voices] return voices
from __future__ import unicode_literals, print_function, division import os import aifc import requests import subprocess from AppKit import NSSpeechSynthesizer, NSURL import xml.etree.ElementTree as ElementTree from bs4 import BeautifulSoup VALID_VOICES = [str(x.replace('com.apple.speech.synthesis.voice.', '')) for x in NSSpeechSynthesizer.availableVoices()] VOICES =['lee.premium', 'fiona.premium', 'emily.premium', 'Alex', 'tom.premium', 'jill.premium', 'sangeeta.premium'] ARXIV_URL = "http://export.arxiv.org/rss/astro-ph" JINGLE = { '[astro-ph.CO]': 'jingles/CO.aiff', '[astro-ph.EP]': 'jingles/EP.aiff', '[astro-ph.GA]': 'jingles/GA.aiff', '[astro-ph.HE]': 'jingles/HE.aiff', '[astro-ph.IM]': 'jingles/IM.aiff', '[astro-ph.SR]': 'jingles/SR.aiff', 'other': 'jingles/other.aiff', } def add_jingle(output_file, subject): jingle = JINGLE.get(subject, JINGLE['other']) with open('tmp_list', 'w') as file_list: file_list.write("file '{0}'\n".format(jingle)) file_list.write("file '{0}'\n".format(output_file)) with open('tmp_log', 'w') as f_log:
from __future__ import unicode_literals, print_function, division import os import aifc import requests import subprocess from AppKit import NSSpeechSynthesizer, NSURL import xml.etree.ElementTree as ElementTree from bs4 import BeautifulSoup VALID_VOICES = [str(x.replace('com.apple.speech.synthesis.voice.', '')) for x in NSSpeechSynthesizer.availableVoices()] VOICES =['lee.premium', 'fiona.premium', 'emily.premium', 'Alex', 'tom.premium', 'jill.premium', 'sangeeta.premium'] ARXIV_URL = "http://export.arxiv.org/rss/astro-ph" HEADERS = {'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1'} JINGLE = { '[astro-ph.CO]': 'jingles/CO.aiff', '[astro-ph.EP]': 'jingles/EP.aiff', '[astro-ph.GA]': 'jingles/GA.aiff', '[astro-ph.HE]': 'jingles/HE.aiff', '[astro-ph.IM]': 'jingles/IM.aiff', '[astro-ph.SR]': 'jingles/SR.aiff', 'other': 'jingles/other.aiff', } def add_jingle(output_file, subject): jingle = JINGLE.get(subject, JINGLE['other']) with open('tmp_list', 'w') as file_list: file_list.write("file '{0}'\n".format(jingle)) file_list.write("file '{0}'\n".format(output_file))
#import pyttsx #engine = pyttsx.init() #engine.say('Good morning.') #engine.runAndWait() from AppKit import NSSpeechSynthesizer print(NSSpeechSynthesizer.availableVoices()) speechSynthesizer = NSSpeechSynthesizer.alloc().initWithVoice_( "com.apple.speech.synthesis.voice.karen") #speechSynthesizer = NSSpeechSynthesizer.alloc().initWithVoice_("com.apple.speech.synthesis.voice.sara") test = speechSynthesizer.startSpeakingString_( 'Hi! Nice to meet you! So how are you today? Feeling anxious. Quite normal considering this is your first time in space. I am sure you will get used to zero gravity within a few weeks. We will all be here to help you through these first critical weeks.' ) #test = speechSynthesizer.startSpeakingString_('Hej, jeg hedder Sara. Jeg er en dansk stemme.') def methods(cls): return [x for x, y in cls.__dict__.items() if type(y) == FunctionType] #print(NSSpeechSynthesizer.__dict__) #print(methods(NSSpeechSynthesizer)) #print(list(dir(NSSpeechSynthesizer))) #print(NSSpeechSynthesizer.__dict__.items()) #attrib = NSSpeechSynthesizer.attributes(voice) #print(voice.attributesforVoice()) #print(type(voice)) #print(dir(voice))
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]
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) synth.setVoice_(voice) RATE += 10 synth.setRate_(RATE)