Exemplo n.º 1
0
def get_next_session(message):
    email = message['email']
    loudness = message['loudness']
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    cursor.execute(
        """insert into sessions(calibrated_rms_value) values(%s);""",
        [loudness])
    cursor.execute("""select LASTVAL();""")
    # xxx convert to fetchone
    session_id = cursor.fetchall()[0][0]
    cursor.execute(
        """select count(*) from users u, sentences s, user_sentence_session us  where s.id = us.sentence_id and u.id = us.user_id and u.email = %s;""",
        [email])
    total_completed = cursor.fetchall()[0][0]
    cursor.execute(
        """select u.session_count from users u where u.email = %s;""", [email])
    sentences_per_session = cursor.fetchall()[0][0]
    hvb_close_db(conn, cursor)
    response = {
        "code": "session",
        "session_id": session_id,
        "completed": total_completed,
        "sentences_per_session": sentences_per_session
    }
    print("response = ", response)
    return response
Exemplo n.º 2
0
def update_opacity(message):
    email = message['email']
    css_id = message['css_id']
    opacity = message['opacity']
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    cursor.execute("""update user_grid_opacity ugo SET increments = increments + 1, opacity = %s from users u, grid g where u.email = %s and ugo.user_id = u.id and ugo.grid_id = g.id and g.css_id = %s;""", [opacity, email, css_id])
    hvb_close_db(conn, cursor)
Exemplo n.º 3
0
def update_opacity(message):
    email = message['email']
    css_id = message['css_id']
    opacity = message['opacity']
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    cursor.execute(
        """update user_grid_opacity ugo SET increments = increments + 1, opacity = %s from users u, grid g where u.email = %s and ugo.user_id = u.id and ugo.grid_id = g.id and g.css_id = %s;""",
        [opacity, email, css_id])
    hvb_close_db(conn, cursor)
Exemplo n.º 4
0
def update_session_count(message):
    email = message['email']
    count = message['count']
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
#    '''update users set password=%(password)s,compendium=%(compendium)s where email=%(email)s''', form_data)
    print("setting the session count to ", count, " of user email = ", email)
    cursor.execute("""update users set session_count=%s where email = %s;""", [count, email])
    hvb_close_db(conn, cursor)
    return None
Exemplo n.º 5
0
def update_session_count(message):
    email = message['email']
    count = message['count']
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    #    '''update users set password=%(password)s,compendium=%(compendium)s where email=%(email)s''', form_data)
    print("setting the session count to ", count, " of user email = ", email)
    cursor.execute("""update users set session_count=%s where email = %s;""",
                   [count, email])
    hvb_close_db(conn, cursor)
    return None
Exemplo n.º 6
0
def update_sentences_completed(message):
    email = message['email']
    sentence_id = message['id']
    session_id = message['session_id']
    loudness = message['loudness']
    rms_value = message['rms_value']
    uri = 'https://s3.amazonaws.com/human-voice-bank'+'/'+email+'/'+message['uri']

    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    make_sentence_update(cursor, email, sentence_id, session_id, loudness, rms_value, uri)
    hvb_close_db(conn, cursor)
Exemplo n.º 7
0
def get_opacity(message):
    email = message['email']
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    cursor.execute("""select g.css_id, ugo.opacity, ugo.increments, ugo.instances from users u, grid g, user_grid_opacity ugo where u.email = %s and u.id = ugo.user_id and g.id = ugo.grid_id;""", [email]);
    raw_data = cursor.fetchall()
    opacity_array = []
    for datum in raw_data:
        opacity_array.append({'id': datum[0], 'opacity': datum[1], 'increments': datum[2], 'instances': datum[3]})

    opacity = {"code": "set-opacity", 'opacity-array': opacity_array}
    hvb_close_db(conn, cursor)
    return opacity
Exemplo n.º 8
0
def get_next_sentence(message):
    email = message['email']
    if 'count' in message:
        count = int(message['count'])
        if count > 100:
            count = 100
    else:
        count = 25

    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    next_block = get_next_block(cursor, email, count)
    hvb_close_db(conn, cursor)
    return next_block
Exemplo n.º 9
0
def update_sentences_completed(message):
    email = message['email']
    sentence_id = message['id']
    session_id = message['session_id']
    loudness = message['loudness']
    rms_value = message['rms_value']
    uri = 'https://s3.amazonaws.com/human-voice-bank' + '/' + email + '/' + message[
        'uri']

    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    make_sentence_update(cursor, email, sentence_id, session_id, loudness,
                         rms_value, uri)
    hvb_close_db(conn, cursor)
Exemplo n.º 10
0
def get_next_sentence(message):
    email = message['email']
    if 'count' in message:
        count = int(message['count'])
        if count > 100:
            count = 100
    else:
        count = 25

    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    next_block = get_next_block(cursor, email, count)
    hvb_close_db(conn, cursor)
    return next_block
Exemplo n.º 11
0
def upload(filename):
    if not ('email' in session):
        return redirect("/", code=302)

    conf = parse_config()        
    _file = request.files['test.wav']
    filename = filename.replace(':', '_')
    filename = session['email']+'-'+filename
    data = _file.stream.read()
    f = open(filename, 'wb+')
    f.write(data)
    f.flush()
    f.close()
    upload_wav_to_s3(conf, data, filename)
    return 'OK'
Exemplo n.º 12
0
def upload(filename):
    if not ('email' in session):
        return redirect("/", code=302)

    conf = parse_config()
    _file = request.files['test.wav']
    filename = filename.replace(':', '_')
    filename = session['email'] + '-' + filename
    data = _file.stream.read()
    f = open(filename, 'wb+')
    f.write(data)
    f.flush()
    f.close()
    upload_wav_to_s3(conf, data, filename)
    return 'OK'
Exemplo n.º 13
0
def get_next_session(message):
    email = message['email']
    loudness = message['loudness']
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    cursor.execute("""insert into sessions(calibrated_rms_value) values(%s);""", [loudness])
    cursor.execute("""select LASTVAL();""")
    # xxx convert to fetchone
    session_id = cursor.fetchall()[0][0]
    cursor.execute("""select count(*) from users u, sentences s, user_sentence_session us  where s.id = us.sentence_id and u.id = us.user_id and u.email = %s;""", [email]);
    total_completed = cursor.fetchall()[0][0];
    cursor.execute("""select u.session_count from users u where u.email = %s;""", [email])
    sentences_per_session = cursor.fetchall()[0][0]
    hvb_close_db(conn, cursor)
    response =  {"code": "session", "session_id": session_id, "completed": total_completed, "sentences_per_session": sentences_per_session}
    print("response = ", response)
    return response
Exemplo n.º 14
0
def get_opacity(message):
    email = message['email']
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    cursor.execute(
        """select g.css_id, ugo.opacity, ugo.increments, ugo.instances from users u, grid g, user_grid_opacity ugo where u.email = %s and u.id = ugo.user_id and g.id = ugo.grid_id;""",
        [email])
    raw_data = cursor.fetchall()
    opacity_array = []
    for datum in raw_data:
        opacity_array.append({
            'id': datum[0],
            'opacity': datum[1],
            'increments': datum[2],
            'instances': datum[3]
        })

    opacity = {"code": "set-opacity", 'opacity-array': opacity_array}
    hvb_close_db(conn, cursor)
    return opacity
Exemplo n.º 15
0
def load():
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf["db"])
    cursor.execute("""select id, sentence, phonetic from sentences;""")
    sentence_tuples = cursor.fetchall()
    hvb_close_db(conn, cursor)
    sentence_meta_list = []
    phoneme_set = set([])
    for id, sentence, phonetic in sentence_tuples:
        sentence_meta = SentenceMeta(id, sentence, phonetic)
        parse_phonemes(sentence_meta, phoneme_set)
        sentence_meta_list.append(sentence_meta)

    phoneme_map = {}
    id = 0
    for phoneme in list(phoneme_set):
        phoneme_map[phoneme] = id
        id += 1

    f = open("phonemes-dml.sql", "w+")
    insert_phonemes(phoneme_map, f)
    insert_sentence_phoneme_join_table(phoneme_map, sentence_meta_list, f)
Exemplo n.º 16
0
def main():
    app.hvb_conf = parse_config()
    app.secret_key = app.hvb_conf['app']['secret_key']
    wsgi_app = WSGIContainer(app)
    server = websock.TornadoWebsocketServer(wsgi_app)
    server.start()
Exemplo n.º 17
0
        for row in reader:
            if first_row:
                schema = row
                print("schema ", schema)
                first_row = False
            else:
                row[1] = row[1].replace('_', ' ')
                #print("ROW = ", row)
                cursor.execute("""insert into sentences(id, display_order, filename, sentence, phonetic, phonemes, flag) values (%s, %s, %s, %s, %s, %s, %s);""",
                               (str(id), str(id), row[0], row[1], row[2], "nothing", row[3]))
                id += 1
        conn.commit()


if __name__ == '__main__':
    conf = parse_config()
    conn, cursor = hvb_connect_db(conf['db'])
    filename = conf['csv']
    print("Database connection established")
    execute_sql(conf['drop'], cursor, conn)
    print("Database dropped")
    execute_sql(conf['create'], cursor, conn)
    print("New schema created")
    #execute_sql(conf['vocalid'], cursor, conn)
    #print("")
    print("Creating sentences table.. ")
    create_sentences_table(filename, cursor, conn)
    print("Generating sentences table.. ")
    generate_sentence_metadata(conn, cursor, conf['phoneme_dml'])
    print("Executing phoneme dml")
    execute_sql(conf['phoneme_dml'], cursor, conn)
Exemplo n.º 18
0
def upload_audio(message):
    try:
        email = message['email']
        filename = message['filename']
        rms = message['rms']
        data = message['data']
        length = int(message['length'])

        pcm_data = []

        for i in range(0, length):
            pcm_data.append(float(data[str(i)]))

        sample_rate = message['sample_rate']
        data = float32_wav_file(pcm_data, sample_rate)

        # f = open("ws-"+filename, 'wb+')
        #    f.write(data)
        #    f.flush()
        #    f.close()

        conf = parse_config()

        conn, cursor = hvb_connect_db(conf['db'])
        userid = ''
        dob = ''
        gender = ''
        platform = 'python-uploader'
        filename_column_field = ''
        full_path = str(email) + '/' + str(filename) + '-' + platform

        try:
            cursor.execute(
                """select u.id, u.dob, u.gender from users u where u.email = %s;""",
                [email])
            userdata = cursor.fetchone()
            print("u.id u.dob, u.gender = ", userdata)
            userid = userdata[0]
            dob = userdata[1]
            gender = userdata[2]
            sentence = filename.split('-')[0]
            cursor.execute(
                """select filename from sentences where sentence = %s;""",
                [sentence])
            filename_column_field = cursor.fetchone()[0]
            filename = str(email) + '/donor' + str(userid) + '-' + str(
                dob) + '-' + str(
                    gender
                ) + '-' + platform + '-' + filename_column_field + '-' + str(
                    filename)

        except Exception as e:
            import sys
            import traceback

            print(
                'TornadoWebsocketHandler: WARNING upload_audio exception generating wave file name with embedded data'
            )
            exc_type, exc_value, exc_traceback = sys.exc_info()
            traceback.print_exception(exc_type,
                                      exc_value,
                                      exc_traceback,
                                      file=sys.stderr)

        full_path = filename

        hvb_close_db(conn, cursor)
        print("fullpath = ", full_path)
        record.upload_wav_to_s3(parse_config(), data, full_path)
    except Exception as e:
        import sys
        import traceback

        print(
            'TornadoWebsocketHandler: WARNING upload_audio exception generating wave file name with embedded data'
        )
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_exception(exc_type,
                                  exc_value,
                                  exc_traceback,
                                  file=sys.stderr)
Exemplo n.º 19
0
def upload_audio(message):
    try:
        email = message['email']
        filename = message['filename']
        rms = message['rms']
        data = message['data']
        length = int(message['length'])

        pcm_data = []

        for i in range(0, length):
            pcm_data.append(float(data[str(i)]))

        sample_rate = message['sample_rate']
        data = float32_wav_file(pcm_data, sample_rate)

        # f = open("ws-"+filename, 'wb+')
        #    f.write(data)
        #    f.flush()
        #    f.close()

        conf = parse_config()

        conn, cursor = hvb_connect_db(conf['db'])
        userid = ''
        dob = ''
        gender = ''
        platform = 'python-uploader'
        filename_column_field = ''
        full_path = str(email) + '/' + str(filename) + '-' + platform

        try:
            cursor.execute("""select u.id, u.dob, u.gender from users u where u.email = %s;""", [email])
            userdata = cursor.fetchone()
            print("u.id u.dob, u.gender = ", userdata)
            userid = userdata[0]
            dob = userdata[1]
            gender = userdata[2]
            sentence = filename.split('-')[0]
            cursor.execute("""select filename from sentences where sentence = %s;""", [sentence])
            filename_column_field = cursor.fetchone()[0]
            filename = str(email) + '/donor' + str(userid) + '-' + str(dob) + '-' + str(
            gender) + '-' + platform + '-' + filename_column_field + '-' + str(filename)

        except Exception as e:
            import sys
            import traceback

            print('TornadoWebsocketHandler: WARNING upload_audio exception generating wave file name with embedded data')
            exc_type, exc_value, exc_traceback = sys.exc_info()
            traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stderr)

        full_path = filename

        hvb_close_db(conn, cursor)
        print("fullpath = ", full_path)
        record.upload_wav_to_s3(parse_config(), data, full_path)
    except Exception as e:
        import sys
        import traceback

        print('TornadoWebsocketHandler: WARNING upload_audio exception generating wave file name with embedded data')
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stderr)