def __init__(self): currentDir = os.path.dirname(os.path.realpath(__file__)) configFile = currentDir + "/../" + self.CONFIG_FILE conf = anyconfig.load(configFile) bconf = bunch.bunchify(conf) self.ttsWatson = TtsWatson(bconf.user, bconf.password, bconf.voice, bconf.url, bconf.chunk)
def main(): requests.packages.urllib3.disable_warnings() defaultConfig = { 'url': 'https://stream.watsonplatform.net/text-to-speech/api', 'user': '******', 'password': '******', 'voice': 'en-US_AllisonVoice', 'chunk': 2048 } home = os.path.expanduser("~") defaultConfigFile = home + '/.config-tts-watson.yml' parser = argparse.ArgumentParser( description='Text to speech using watson') parser.add_argument('-f', action='store', dest='configFile', default=defaultConfigFile, help='config file', required=False) parser.add_argument('text_to_transform', action='store', nargs='+') args = parser.parse_args() conf = anyconfig.container(defaultConfig) if not os.path.isfile(args.configFile): print "Config file '" + args.configFile + "' doesn't exist." print "Creating it ..." user = raw_input("Watson user: "******"Watson password: "******" ".join(args.text_to_transform))
def __init__(self, robot, text='coucou', lang='fr', ttsengine='google'): pypot.primitive.Primitive.__init__(self, robot) self._text = text.decode('utf-8') self._lang = lang.decode('utf-8') self._ttsengine = ttsengine.decode('utf-8') self.ttsWatson = TtsWatson('c18c9e2a-25ae-4e3d-9cb0-7281a19d1f7b', 'Tc5kBRiUuTz5', 'fr-FR_ReneeVoice')
class TtsWatsonRos: CONFIG_FILE = "config.yml" def __init__(self): currentDir = os.path.dirname(os.path.realpath(__file__)) configFile = currentDir + "/../" + self.CONFIG_FILE conf = anyconfig.load(configFile) bconf = bunch.bunchify(conf) self.ttsWatson = TtsWatson(bconf.user, bconf.password, bconf.voice, bconf.url, bconf.chunk) def playSound(self, data): self.ttsWatson.play(data.data)
class TtsWatsonRos: CONFIG_FILE = "config1.yml" def __init__(self): currentDir = os.path.dirname(os.path.realpath(__file__)) configFile = currentDir + "/../" + self.CONFIG_FILE conf = anyconfig.load(configFile) bconf = bunch.bunchify(conf) self.ttsWatson = TtsWatson(bconf.user, bconf.password, bconf.voice, bconf.url, bconf.chunk) def playSound(self, data): print("hi") #self.ttsWatson.play('hello') self.ttsWatson.play(data.data)
class TtsWatsonRos: CONFIG_FILE = "config.sample.yml" def __init__(self): currentDir = os.path.dirname(os.path.realpath(__file__)) configFile = currentDir + "/../" + self.CONFIG_FILE conf = anyconfig.load(configFile) bconf = bunch.bunchify(conf) self.ttsWatson = TtsWatson(bconf.user, bconf.password, bconf.voice, bconf.url, bconf.chunk) def playSound(self, data): if data.data == True: self.ttsWatson.play("Requested action executed") else: self.ttsWatson.play("No command to execute")
def __init__(self, robot, text='coucou', lang='fr', ttsengine='watson'): pypot.primitive.Primitive.__init__(self, robot) self._text = text.decode('utf-8') self._lang = lang.decode('utf-8') # TTS self._ttsengine = ttsengine.decode('utf-8') self.ttsWatson = TtsWatson('28d3342c-5436-4cdb-a587-40da89f80afa', 'EKNVJxa0KbZB', 'fr-FR_ReneeVoice') self._rate = 24000 print "INIT" print text, type(text) print text.decode('utf-8'), type(text.decode('utf-8')) print "FIN INIT"
def main(): py3_input_conversion = lambda x: input( x) if sys.version_info.major >= 3 else raw_input(x) requests.packages.urllib3.disable_warnings() defaultConfig = { 'url': 'https://stream.watsonplatform.net/text-to-speech/api', 'user': '******', 'password': '******', 'voice': 'en-US_AllisonVoice', 'chunk': 2048 } home = os.path.expanduser("~") defaultConfigFile = home + '/.config-tts-watson.yml' parser = argparse.ArgumentParser(description='Text to speech using watson') parser.add_argument('-f', action='store', dest='configFile', default=defaultConfigFile, help='config file', required=False) parser.add_argument('text_to_transform', action='store', nargs='+') args = parser.parse_args() conf = anyconfig.container(defaultConfig) if not os.path.isfile(args.configFile): print("Config file '" + args.configFile + "' doesn't exist.") print("Creating it ...") user = py3_input_conversion("Watson user: "******"Watson password: "******" ".join(args.text_to_transform))
class TtsWatsonRos: CONFIG_FILE = "config1.yml" global pre pre = 1 def __init__(self): currentDir = os.path.dirname(os.path.realpath(__file__)) configFile = currentDir + "/../" + self.CONFIG_FILE conf = anyconfig.load(configFile) bconf = bunch.bunchify(conf) self.ttsWatson = TtsWatson(bconf.user, bconf.password, bconf.voice, bconf.url, bconf.chunk) def playSound(self, data): global user_input global context print(data.data) #if(pre!=data.data): i = 0 while True: i = i + 1 if i > 5: break # Send message to Assistant service. user_input = data.data response = service.message(workspace_id=workspace_id, input={'text': user_input}, context=context) # If an intent was detected, print it to the console. if response.result['intents']: print('Detected intent: #' + response.result['intents'][0]['intent']) # Print the output from dialog, if any. Assumes a single text response. if response.result['output']['text']: print(response.result['output']['text'][0]) self.ttsWatson.play(response.result['output']['text'][0]) break # Update the stored context with the latest received from the dialog. context = response.result['context']
def play(request): if request.method == "POST": tex = request.POST.get("speak") ttsWatson = TtsWatson('42657070-d2ed-4d8d-bac3-05d505e42b9a', 'ePrw5TcBlL6N', 'en-US_AllisonVoice') num = word_tokenize(tex) numlength = len(num) - 1 tcount = 0 newtex = "" for n in num: word = n.lower() sent = "".join(word) if tcount == 0: newtex = newtex + sent else: newtex = newtex + " " + sent tcount += 1 print(newtex) memo = Memory.objects.filter(query=newtex) if len(tex) != 0 and memo: for me in memo: ttsWatson.play(me.reply) return render(request, "page/index.html") else: ttsWatson.play("Sorry, I didn't understand") return render(request, "page/index.html") else: return render(request, "page/front.html")
from tts_watson.TtsWatson import TtsWatson ttsWatson = TtsWatson('*****@*****.**', 'P652568323', 'en-US_AllisonVoice') ttsWatson.play('Hello World')
text_a = open("input.txt").read() text_b = open("input2.txt").read() import os import markovify import time import subprocess import itertools import requests import json from watson_developer_cloud import TextToSpeechV1 text_to_speech = TextToSpeechV1( iam_apikey='sz6H8LevNTGD8wn8_fBqFZ61lrUDtuHAFwuD1TFaguPr', url='https://gateway-wdc.watsonplatform.net/text-to-speech/api') from tts_watson.TtsWatson import TtsWatson tts = TtsWatson("**Username**", "**Password**", "en-US_Allisonvoice") tts.play("Test")
def alison_speak(self, text): engine = TtsWatson(self.watson_username, self.watson_password, 'en-US_AllisonVoice') engine.play(text) pass
from tts_watson.TtsWatson import TtsWatson ttsWatson = TtsWatson( '*****@*****.**', 'Nnnoman@007', 'en-US_AllisonVoice' ) # en-US_AllisonVoice is a voice from watson you can found more to: https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/text-to-speech/using.shtml#voices ttsWatson.play("The text which i want to be a sound")
class Speak(pypot.primitive.Primitive): properties = pypot.primitive.Primitive.properties + [ 'sentence_to_speak', 'language', 'tts_engine' ] def __init__(self, robot, text='coucou', lang='fr', ttsengine='google'): pypot.primitive.Primitive.__init__(self, robot) self._text = text.decode('utf-8') self._lang = lang.decode('utf-8') self._ttsengine = ttsengine.decode('utf-8') self.ttsWatson = TtsWatson('c18c9e2a-25ae-4e3d-9cb0-7281a19d1f7b', 'Tc5kBRiUuTz5', 'fr-FR_ReneeVoice') def start(self): #self._text = text.decode('utf-8', errors='replace') pypot.primitive.Primitive.start(self) def run(self): filename = 'Phrase1.mp3' # Use GOOGLE as a tts engine if (self._ttsengine == "google"): tts = gTTS((self._text), lang=self._lang) tts.save(filename) print "Play with Google" # Use WATSON as a tts engine if (self._ttsengine == "watson"): #ttsWatson = TtsWatson('c18c9e2a-25ae-4e3d-9cb0-7281a19d1f7b', 'Tc5kBRiUuTz5', 'fr-FR_ReneeVoice') self.ttsWatson.save(filename, (self._text)) #ttsWatson.play((self._text)) print "Play with Watson" clip = mp3play.load(os.path.abspath('Phrase1.mp3')) clip.play() while clip.isplaying() is not False: time.sleep(0.5) #pygame.mixer.init(16000) #pygame.mixer.music.load(os.path.abspath(filename)) #pygame.mixer.music.set_volume(0.8) #pygame.mixer.music.play() #while pygame.mixer.music.get_busy(): # time.sleep(0.5) #pygame.mixer.music.stop() #pygame.mixer.quit() #mp3 = pyglet.media.load(filename) #mp3.play() # wait until terminated #time.sleep(mp3.duration) @property def sentence_to_speak(self): return self._text @sentence_to_speak.setter def sentence_to_speak(self, text): print text text.encode('utf-8') self._text = text @property def language(self): return self._lang @language.setter def language(self, lang): print "Now, I speak " + lang lang.encode('utf-8') self._lang = lang @property def tts_engine(self): return self._ttsengine @tts_engine.setter def tts_engine(self, engine): print "Now, my TTS engine is: " + engine engine.encode('utf-8') self._ttsengine = engine
CONSUMER_KEY = "#YourConsumerKeyFromTwitter" CONSUMER_SECRET = "#YourConsumerSecretFromTwitter" ACCESS_KEY = "#YourAccesKeyFromTwitter" ACCESS_SECRET = "#YourAccesSecretFromTwitter" AUX1 = "" AUX2 = "" consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET) access_token = oauth.Token(key=ACCESS_KEY, secret=ACCESS_SECRET) client = oauth.Client(consumer,access_token) timeline_endpoint = "https://api.twitter.com/1.1/search/tweets.json?q=%23SaturdayIBMProgramming" ttsWatson = TtsWatson('userfromwatson', 'passwordfromwatson', 'en-US_AllisonVoice') def remove_accents(input_str): nkfd_form = unicodedata.normalize('NFKD', input_str) only_ascii = nkfd_form.encode('ASCII', 'ignore') return only_ascii while 1: try: response, data = client.request(timeline_endpoint) data = json.loads(data) usernameTw = remove_accents(data['statuses'][0]['user']['screen_name']) textoTw = remove_accents(data['statuses'][0]['text']) if AUX1!=textoTw or AUX2!=usernameTw: print "Read Twitter"
API_KEY = "ac3a58fe09a54c6fb568546f4d0c0674" endpoint = 'https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect' args = { 'returnFaceId': 'true', 'returnFaceLandmarks': 'false', 'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,' + 'emotion,hair,makeup,occlusion,accessories,blur,exposure,noise' } headers = { 'Content-Type': 'application/octet-stream', 'Ocp-Apim-Subscription-Key': API_KEY } ttsWatson = TtsWatson('0ceb1e44-e69d-4781-8eb9-e214cc8e4389', 'gNFDi45r1APE', 'en-US_AllisonVoice') start = time.time() ### CAPTURE VIDEO cam = cv2.VideoCapture(0) while True: if cv2.waitKey(1) & 0xFF == ord('q'): break time.sleep(1) ret, img = cam.read() img = cv2.flip(img, 1) cv2.imshow('Frame', img) scaling_factor = 0.25 img = cv2.resize(img, None, fx=scaling_factor,
from gtts import gTTS import os #tts = gTTS(text="Good morning", lang="en") from tts_watson.TtsWatson import TtsWatson userName = "******" password = "******" ttsWatson = TtsWatson(userName, password, "en-AllisonVoice") text = 'Hello world' ttsWatson.play(text)
from tts_watson.TtsWatson import TtsWatson ttsWatson = TtsWatson( '*****@*****.**', 'winRISD1', 'en-US_AllisonVoice' ) # en-US_AllisonVoice is a voice from watson you can found more to: https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/text-to-speech/using.shtml#voices ttsWatson.play("The text which i want to be a sound")
print("Google Speech Recognition thinks you said " + msg) except sr.UnknownValueError: print("Google Speech Recognition could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) #msg = r.recognize_google(audio,language='FR').encode("utf-8") #print "Message " + msg if msg: params = urllib.urlencode({'msg':msg}) print "\nUtilisateur : " + msg print "J'envois la requête" #urllib2.urlopen('http://localhost:8080/chatterbot',params) response = sendToChatterbot(msg); requests.packages.urllib3.disable_warnings(InsecureRequestWarning) print "\n Bot : "+response response = response.encode('utf-8') # engine = pyttsx.init() # engine.setProperty('rate', 150) # engine.say(response) # engine.runAndWait() ttsWatson = TtsWatson('c7b754a7-30af-478b-ad09-50d6599fee4a', '4PiXRAE4QPpU', 'fr-FR_ReneeVoice') ttsWatson.play(response) print "Requête délivrée" msg = "" else: print "Pas de message"
class Speak(pypot.primitive.Primitive): properties = pypot.primitive.Primitive.properties + [ 'sentence_to_speak', 'language', 'tts_engine' ] def __init__(self, robot, text='coucou', lang='fr', ttsengine='watson'): pypot.primitive.Primitive.__init__(self, robot) self._text = text.decode('utf-8') self._lang = lang.decode('utf-8') # TTS self._ttsengine = ttsengine.decode('utf-8') self.ttsWatson = TtsWatson('28d3342c-5436-4cdb-a587-40da89f80afa', 'EKNVJxa0KbZB', 'fr-FR_ReneeVoice') self._rate = 24000 print "INIT" print text, type(text) print text.decode('utf-8'), type(text.decode('utf-8')) print "FIN INIT" #def start(self, text): def start(self): #self._text = text.decode('utf-8', errors='replace') pypot.primitive.Primitive.start(self) def run(self): if self._text == None: print "pas de texte" else: print "START" print "self._text", type(self._text) print "Bitrate: " + str(self._rate) filename_temp = find(reader, self._text) filename = mp3_dir + filename_temp #filename = self._filename #print filename pygame.mixer.init(self._rate) pygame.mixer.music.load(os.path.abspath(filename)) pygame.mixer.music.set_volume(0.8) pygame.mixer.music.play() while pygame.mixer.music.get_busy(): time.sleep(0.1) pygame.mixer.quit() @property def sentence_to_speak(self): return self._text @sentence_to_speak.setter def sentence_to_speak(self, text): if text == "": self._filename = None else: print "CHANGE TEXT" print type(text), text.encode('utf-8') #print text.decode('utf-8'), type(text.decode('utf-8')) print "FIN CHANGE TEXT" self._text = text file = open(csv_file_name, "a+") reader = csv.DictReader(file) file.seek(0) filename_temp = find(reader, self._text, self._lang, self._ttsengine) if filename_temp: self._filename = mp3_dir + filename_temp else: filename_temp = self._ttsengine + "_" + self._lang + "_" + str( randint(1, 99999)) + ".mp3" filename = mp3_dir + filename_temp print "DEBUT GENERATION" if (self._ttsengine == "google"): tts = gTTS(self._text, lang=self._lang) tts.save(filename) #self._rate = 24000 print "Play with Google" if (self._ttsengine == "watson"): self.ttsWatson.save(filename, (self._text)) print "Play with Watson" if (self._ttsengine == "pico"): if (self._lang == "en"): lang = 'en-US' else: lang = 'fr-FR' filename_temp = filename_temp.replace(".mp3", ".wav") filename = filename.replace(".mp3", ".wav") print filename cmd = 'pico2wave -l=' + lang + ' -w=' + filename + ' "' + self._text + '"' + ' || echo "No .wav file created"' subprocess.call(cmd, shell=True) #self._rate = 16000 print "Play with Pico" print "nouvelle entrée" new = (self._text.encode('utf-8'), filename_temp) print new w = csv.writer(file) w.writerow(new) self._filename = filename print "FIN GENERATION" @property def language(self): return self._lang @language.setter def language(self, lang): print "Now, I speak " + lang lang.encode('utf-8') self._lang = lang if (self._ttsengine == "watson"): self.ttsWatson.set_spoken_language(lang) @property def tts_engine(self): return self._ttsengine @tts_engine.setter def tts_engine(self, engine): engine.encode('utf-8') self._ttsengine = engine if (engine == "google"): self._rate = 24000 if (engine == "watson"): self._rate = 22050 if (engine == "pico"): self._rate = 16000 print "Now, my TTS engine is: " + engine + " and the bitrate is: " + str( self._rate)
from tts_watson.TtsWatson import TtsWatson ttsWatson = TtsWatson('', '', 'en-US_AllisonVoice') texttospeak = 'Aman Dalal' a = ttsWatson.play(texttospeak)
from tts_watson.TtsWatson import TtsWatson ttsWatson = TtsWatson('5b8523f8-4396-41a2-b3d6-704bf47567cb', 'u0H6TzFeo3kz', 'en-US_AllisonVoice') texttospeak = 'Aman Dalal' a = ttsWatson.play(texttospeak)
from tts_watson.TtsWatson import TtsWatson ttsWatson = TtsWatson('watson_user', 'watson_password', 'en-US_AllisonVoice') ttsWatson.play("Hello World")
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Boucle permettant de tenir une conversation avec le robot #pico = 'sh ~/Documents/Cherry/pico.sh' #Chemin vers le script pico, qui lance pico2wave import sys import os import pypot import urllib2 import urllib import pyttsx import string from tts_watson.TtsWatson import TtsWatson # import requests # from requests.packages.urllib3.exceptions import InsecureRequestWarning #requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # engine = pyttsx.init() # engine.setProperty('rate', 150) # engine.say(response) # engine.runAndWait() ttsWatson = TtsWatson('9ab9e322-6ac9-4d11-a93f-10c19667a013', 'G4QF16oBGpIC', 'fr-FR_ReneeVoice') # chaine = "" # tab = sys.argv[1].split("_"); # for i in tab : # chaine+=i+" " # ttsWatson.play(chaine.encode('utf-8')) ttsWatson.play("Bonjour")