Пример #1
0
def find_server_on_network():
    global server_ip

    ip = socket.gethostbyname(socket.gethostname())

    # sometimes it might return the local ip (127.0.0.1) adding local should solves that
    # TODO: see if we only use the ".local" ip
    if ip.startswith("127.0"):
        ip = socket.gethostbyname(socket.gethostname() + ".local")

    if ip.startswith("192.168.1"):
        server_ip = find_device_on_network_with_opened_port(
            ipaddress.ip_network("192.168.1.0/24"),
            config_utils.get_in_config('SERVER_PORT'))
    elif ip.startswith("172.16"):
        server_ip = find_device_on_network_with_opened_port(
            ipaddress.ip_network("172.16.0.0/12"),
            config_utils.get_in_config('SERVER_PORT'))
    elif ip.startswith("10."):
        print(
            "Warning: scanning for server on a huge network, please specify the server's ip in the config.json asap."
        )
        server_ip = find_device_on_network_with_opened_port(
            ipaddress.ip_network("10.0.0.0/8"),
            config_utils.get_in_config('SERVER_PORT'))
    if server_ip is None:
        return None

    server_ip = server_ip.compressed
    return server_ip
Пример #2
0
def get_server_ip():
    global server_ip

    if server_ip is not None:
        return server_ip

    if config_utils.get_in_config('SERVER_IP') is None:
        print(
            "No server IP specified in config, looking trough the entire network... (might take a few seconds)"
        )
        result = find_server_on_network()
        if result is not None:
            print("Found server on : " + result)
            server_ip = result
            return result
        else:
            sys.exit("Server not found!")
    else:
        return config_utils.get_in_config('SERVER_IP')
Пример #3
0
def send_record_to_server(raw_audio_data):
    url_service = "http://" + str(get_server_ip()) + ":" + str(
        get_server_port()) + "/process_audio_request"

    headers = CaseInsensitiveDict()
    headers["Content-Type"] = "text/xml; charset=utf8"
    headers['Client-Ip'] = socket.gethostbyname(socket.gethostname())
    headers['Client-Port'] = str(config_utils.get_in_config('PORT'))
    # headers["Authorization"] = config_utils.get_in_config("API_KEY")

    response = requests.post(url_service, headers=headers, data=raw_audio_data)

    print(bytes.decode(response.content))
Пример #4
0
def what_time_is_it():
    tag = 'what_time_is_it'
    response = intents_utils.get_response(tag)

    current_time = time.localtime()

    if config_utils.get_in_config("12HOURS-FORMAT"):
        response = response.replace('{time}',
                                    time.strftime("%I:%M %p", current_time))
    else:
        response = response.replace('{time}',
                                    time.strftime("%H:%M", current_time))

    return response
Пример #5
0
def get_audio_from_sentence(sentence):
    voice = config_utils.get_in_config("TTS_VOICE")

    headers = {'accept': '*/*'}

    params = (
        ('voice', voice),
        ('text', sentence),
    )

    # TODO : add support for external opentts server
    try:
        response = requests.get('http://localhost:5500/api/tts',
                                headers=headers,
                                params=params)
        return response.content
    except requests.exceptions.ConnectionError:
        print("Error connecting to Open TTS server")
        return None
Пример #6
0
def send_sentence_to_server(sentence):
    url_service = "http://" + str(get_server_ip()) + ":" + str(
        get_server_port()) + "/process_text_request"

    headers = CaseInsensitiveDict()
    headers["Content-Type"] = "application/json; charset=utf8"
    headers['Client-Ip'] = socket.gethostbyname(socket.gethostname())
    headers['Client-Port'] = str(config_utils.get_in_config('PORT'))
    # headers["Authorization"] = config_utils.get_in_config("API_KEY")

    try:
        response = requests.post(url_service,
                                 headers=headers,
                                 json={'sentence': sentence})

        print(bytes.decode(response.content))
    except ConnectionError:
        print(
            "Error connecting to the server (server was probably shutdown during request)..."
        )
Пример #7
0
import re
import string
from difflib import SequenceMatcher

import spotipy
from lingua_franca.parse import fuzzy_match
from spotipy import SpotifyOAuth

from jarvis.utils import config_utils

scope = "user-read-playback-state, user-modify-playback-state, user-read-currently-playing"

# TODO: Investigate the open_browser and automatic auth renewing without user interaction
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
    scope=scope,
    client_id=config_utils.get_in_config("SPOTIFY_CLIENT_ID"),
    client_secret=config_utils.get_in_config("SPOTIFY_CLIENT_SECRET"),
    redirect_uri='http://localhost:8888/callback/',
    open_browser=False))


def get_spotify():
    return sp


def query_song(song=None, artist=None):
    if song is not None and artist is not None:
        query = '*{}* artist:{}'.format(song, artist)
    elif song is None and artist is not None:
        query = "artist:" + artist
    elif song is not None and artist is None:
Пример #8
0
def get_server_port():
    return config_utils.get_in_config('SERVER_PORT') if not None else 5000
Пример #9
0
def start_server():
    app.config['JSON_AS_ASCII'] = False
    app.run(port=config_utils.get_in_config("PORT"), debug=False, host='0.0.0.0', threaded=True)