def listen_to_word(self): lang = self.foreign_language_code if (self.isEnglish): lang = "en" speech_object = text_to_speech.TextToSpeech( self.translated_text.text(), lang) speech_object.speech()
def working2(event): while (True): text1 = stt.SpeechToText() print "YOU: " + text1 if (text1.upper() == "BYE ") or (text1.upper() == "QUIT ") or ( text1.upper() == "BYE") or (text1.upper() == "QUIT"): break else: text2 = Eliza_Algo.Heart(text1) print "BOT: " + text2 text_to_speech.TextToSpeech(text2, 1)
def send_word(self, event): print(self.entryBox.get()) print("pitch") print(type(int(self.pitch_val))) params = { "text": self.entryBox.get(), # 200文字以内 "speaker": self.speaker, # 話者名 #"emotion": "happiness", # 感情 #"emotion_level": 4, # 感情レベル "pitch": int(self.pitch_val) + 50, # 音の高さ "speed": int(self.speed_val) + 50, # 音声の速度 "volume": int(self.volume_val) + 50 # 音声の大きさ } print(params) speech = tts.TextToSpeech(params) path = speech.text_to_speech() # wavファイル self.wav_file = path
addresses_path = os.environ.get('ADDRESSES_PATH', 'addresses.pickle') speech_path = os.environ.get('SPEECH_PATH', 'speech') try: addresses = pickle.load(open(addresses_path, 'rb')) if isinstance(addresses, set): addresses = {address: {'currency': 'USD'} for address in addresses} except: addresses = dict() address_websockets = dict() wallet = wallet.WalletDefault() wallet.add_addresses( [Address.from_string(address) for address in addresses.keys()]) exchange_rates = exchange_rate.ExchangeRateBitcoinCom() currency_infos = exchange_rate.CurrenciesInfoFixed() speech = text_to_speech.TextToSpeech(speech_path) pool = ThreadPoolExecutor(10) def format_bch_amount(satoshis: int): fract_part = satoshis % 100_000_000 fract_part_str = '{:0>8d}'.format(fract_part) parts = fract_part_str[:3], fract_part_str[3:6], fract_part_str[6:] for i, part in reversed(list(enumerate(parts))): if any(char != '0' for char in part): parts = parts[:i + 1] break else: parts = () whole_part = satoshis // 100_000_000 fract_part_str = '\xa0'.join(parts)
def process_cmds(): # Creates an instance of a speech config with specified subscription key and service region. # Replace with your own subscription key and service region (e.g., "westus"). player = text_to_speech.TextToSpeech() player.get_token() speech_key, service_region = "ae06249641924ee8bfebd863b121f33c", "eastus" speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region) # Creates a recognizer with the given settings speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config) flag = 1 auth = True invalidUID = True invalidPW = True counter = 0 while (auth): while (invalidUID): # ask UID player.save_audio("Hello. Please state your member number.") result = speech_recognizer.recognize_once() # Checks result. if result.reason == speechsdk.ResultReason.RecognizedSpeech: print("Recognized: {}".format(result.text)) elif result.reason == speechsdk.ResultReason.NoMatch: print("No speech could be recognized: {}".format(result.no_match_details)) elif result.reason == speechsdk.ResultReason.Canceled: cancellation_details = result.cancellation_details print("Speech Recognition canceled: {}".format(cancellation_details.reason)) if cancellation_details.reason == speechsdk.CancellationReason.Error: print("Error details: {}".format(cancellation_details.error_details)) time.sleep(10) userID = result.text.replace(".", "").replace(",", "") print(userID) if (len(userID) > 0): invalidUID = False while (invalidPW): # ask password player.save_audio("Hello. Please state your password.") result = speech_recognizer.recognize_once() # Checks result. if result.reason == speechsdk.ResultReason.RecognizedSpeech: print("Recognized: {}".format(result.text)) elif result.reason == speechsdk.ResultReason.NoMatch: print("No speech could be recognized: {}".format(result.no_match_details)) elif result.reason == speechsdk.ResultReason.Canceled: cancellation_details = result.cancellation_details print("Speech Recognition canceled: {}".format(cancellation_details.reason)) if cancellation_details.reason == speechsdk.CancellationReason.Error: print("Error details: {}".format(cancellation_details.error_details)) time.sleep(10) password = result.text.lower().replace(" ", "").replace(".", "") print(password) if (len(password) > 0): invalidPW = False try: val = SQLTest.get_auth(userID, password) if (val is not None): auth = False except: player.save_audio("Invalid login") invalidUID = True invalidPW = True counter += 1 if (counter > 5): break # Starts speech recognition, and returns after a single utterance is recognized. The end of a # single utterance is determined by listening for silence at the end or until a maximum of 15 # seconds of audio is processed. The task returns the recognition text as result. # Note: Since recognize_once() returns only a single utterance, it is suitable only for single # shot recognition like command or query. # For long-running multi-utterance recognition, use start_continuous_recognition() instead. while flag: player.save_audio('What would you like to do') result = speech_recognizer.recognize_once() # Checks result. if result.reason == speechsdk.ResultReason.RecognizedSpeech: print("Recognized: {}".format(result.text)) elif result.reason == speechsdk.ResultReason.NoMatch: print("No speech could be recognized: {}".format(result.no_match_details)) elif result.reason == speechsdk.ResultReason.Canceled: cancellation_details = result.cancellation_details print("Speech Recognition canceled: {}".format(cancellation_details.reason)) if cancellation_details.reason == speechsdk.CancellationReason.Error: print("Error details: {}".format(cancellation_details.error_details)) if 'quit' in result.text.lower(): flag = 0 player.save_audio('Thank you for your business') break player.save_audio(result.text) c = text_to_cmd.return_command_type(result.text) #player.save_audio(c) cmd_type = 'not a command' if (c=="cmd_type"): #if result.text #player.save_audio('Could not interpret command') continue else: #SQLTest.deal_with_switch('balance', result.text) player.save_audio(SQLTest.deal_with_switch(c,result.text)) player.save_audio("Say quit, to, end.") # TODO Add quit to commands # </code>
def pronun_in_for1(self): lang = self.foreign_language_code speech_object = text_to_speech.TextToSpeech(self.foreign_1.text(), lang) speech_object.speech()
def pronun_in_eng1(self): speech_object = text_to_speech.TextToSpeech(self.english_1.text(), "en") speech_object.speech()
def pronunciation(self): lang = self.foreign_language_code speech_object = text_to_speech.TextToSpeech(self.input.text(),lang) speech_object.speech()