Skip to content

Commit

Permalink
fix a lot of stuff with IM
Browse files Browse the repository at this point in the history
  • Loading branch information
thealphadollar committed Oct 20, 2019
1 parent fc2fccf commit 8b47b4f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 340 deletions.
11 changes: 7 additions & 4 deletions IM4All/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import uuid
from flask import Flask, render_template, session, request, url_for, current_app
import wave
import uuid
import os
from gtts import gTTS
from flask_socketio import SocketIO, emit, join_room
Expand Down Expand Up @@ -37,11 +38,12 @@ def test_connect():
def chat_to_aud(message):
print(message)
audio = gTTS(message)
audio.save(os.path.join(dir_path, 'static', '_files', 'message.wav'))
name = str(uuid.uuid1()) + ".wav"
audio.save(os.path.join(dir_path, 'static', '_files', name))
print("done")
emit('add-wavefile', url_for('static',
filename='_files/' + 'message.wav'))
os.remove(os.path.join(dir_path, 'static', '_files', 'message.wav'))
filename='_files/' + name), broadcast=True)
# os.remove(os.path.join(dir_path, 'static', '_files', 'message.wav'))

@socketio.on('start-recording', namespace='/chat')
def start_recording(options):
Expand All @@ -52,6 +54,7 @@ def start_recording(options):
wf.setnchannels(options.get('numChannels', 1))
wf.setsampwidth(options.get('bps', 16) // 8)
wf.setframerate(options.get('fps', 44100))

session['wavefile'] = wf


Expand Down Expand Up @@ -83,7 +86,7 @@ def end_recording():
text = getTextFromAudio(
url_for('static', filename='_files/' + session['wavename']))
print(text)
emit('message', {'data': { 'message': text, 'author': 'IM4ALL' }}, broadcast=True)
emit('message', {'data': { 'message': text, 'author': 'by IM4ALL' }}, broadcast=True)
print('here')
session['wavefile'].close()
del session['wavefile']
Expand Down
9 changes: 7 additions & 2 deletions IM4All/static/assets/js/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ socket.on("message", function (message) {
});

function refreshMessages(message) {
$(".media-list").append('<li class="media"><div class="media-body"><div class="media"><div class="media-body">'
$(".media-list").append('<li class="media"><div class="media-body"><div class="media"><div class="media-body">' + message.data.author + ": "
+ message.data.message + '<br/><small class="text-muted">' + message.data.author + '</small><hr/></div></div></div></li>');
}

$(function () {

$('form input').on('keypress', function(e) {
return e.which !== 13;
});

if (typeof $.cookie("realtime-chat-nickname") === 'undefined') {
window.location = "/login"
} else {
Expand All @@ -60,6 +64,7 @@ if (typeof $.cookie("realtime-chat-nickname") === 'undefined') {

$('#messageText').keyup(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
sendMessage();
}
});
Expand All @@ -69,7 +74,7 @@ function sendMessage() {
$container = $('.media-list');
$container[0].scrollTop = $container[0].scrollHeight;
var message = $("#messageText").val();
var author = $.cookie("realtime-chat-nickname");
var author = "by " + $.cookie("realtime-chat-nickname");
socket.emit('message', { data: { message: message, author: author } });
socket.emit('chat-to-aud', message);
$("#messageText").val("");
Expand Down
217 changes: 0 additions & 217 deletions IM4All/static/assets/js/speech2text.js

This file was deleted.

6 changes: 3 additions & 3 deletions IM4All/templates/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ <h1><a href="https://web.jvank.now.sh/">Connect All</a></h1>
<!-- Main -->
<article id="main">
<header>
<h2>Narration</h2>
<p>Text to speech narration</p>
<h2>Instant Messenger For All</h2>
<p>Deepen Your Connections With Loved Ones</p>
</header>
<section id="three" class="wrapper style3 special">
<div class="inner">
<header class="major">
<h2>CHAT AND FLIRT</h2>
<h2>CHAT</h2>

<div id="viz">
<canvas id="analyser" width="1024" height="500"></canvas>
Expand Down
Loading

0 comments on commit 8b47b4f

Please sign in to comment.