Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import socket
- import pyvona
- import time
- from assertions import host_addr, port_addr, twitch_user, oauth, access_key, secret_key, voice_pack, language, max_message_duration, volume, message_delay, log_file, log_enabled, ivona_enabled
- lg = language
- vol = float(volume)
- c = int(max_message_duration)
- HOST = host_addr
- PORT = int(port_addr)
- NICK = twitch_user
- PASS = oauth
- v = pyvona.create_voice(access_key, secret_key)
- v.voice_name = voice_pack
- def send_message(message):
- s.send(bytes("PRIVMSG #" + NICK + " :" + message + "\r\n", "UTF-8"))
- #start the function here for the future
- s = socket.socket()
- s.connect((HOST, PORT))
- s.send(bytes("PASS " + PASS + "\r\n", "UTF-8"))
- s.send(bytes("NICK " + NICK + "\r\n", "UTF-8"))
- s.send(bytes("JOIN #" + NICK + " \r\n", "UTF-8"))
- while True:
- line = str(s.recv(1024))
- if "End of /NAMES list" in line:
- break
- while True:
- for line in str(s.recv(1024)).split('\\r\\n'):
- parts = line.split(':')
- if len(parts) < 3:
- continue
- if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
- message = parts[2][:len(parts[2])]
- usernamesplit = parts[1].split("!")
- username = usernamesplit[0]
- # Force delay between messages if invoked by the config
- afix = int(message_delay)
- time.sleep(afix)
- print(username + ": " + message)
- if message == "Hey":
- send_message("Welcome!," + username)
- # chat log parser: check if logging is enabled
- from assertions import log_enabled
- if log_enabled == "1":
- from assertions import log_file
- from datetime import datetime
- timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
- # begin logging
- # begin function here:
- file = open(log_file, "a")
- file.write(timestamp + " " + username + ": " + message + '\n')
- file.close()
- if ivona_enabled == "0":
- import pygame as pg
- from gtts import gTTS
- wrapper = username + 'said:' + message
- def test_voice(music_file, volume=0.8):
- '''
- stream music with mixer.music module in a blocking manner
- this will stream the sound from disk while playing
- '''
- # set up the mixer
- pg.mixer.init()
- # volume value 0.0 to 1.0
- pg.mixer.music.set_volume(volume)
- clock = pg.time.Clock()
- try:
- pg.mixer.music.load(music_file)
- except pg.error:
- print("File {} not found! ({})".format(music_file, pg.get_error()))
- return
- pg.mixer.music.play()
- while True:
- pg.mixer.init()
- if pg.mixer.music.get_busy() == True:
- print("playing")
- if pg.mixer.music.get_busy() == False:
- print ("ended")
- pg.mixer.quit()
- break
- pg.mixer.init()
- # give the full file path
- # (try other sound file formats too)
- music_file = "temp.mp3"
- # optional volume 0 to 1.0
- volume = vol
- tts = gTTS(text=wrapper, lang=lg)
- tts.save(music_file)
- test_voice(music_file, volume)
- else:
- name = username + 'said,'
- v.speak(name + message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement