Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTS and STT Support for PyKlatchat #39

Merged
merged 28 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
395def4
Added initial structure for STT/TTS support
kirgrim Jul 11, 2022
e3593e0
dropped legacy camelCased message text
kirgrim Jul 11, 2022
3045f04
Fixed neon recipient resolver to handle stt and tts properly
kirgrim Jul 14, 2022
716cd4a
Merge branch 'dev' into tts_support
NeonKirill Jul 14, 2022
0f5a5c4
Merge branch 'dev' into tts_support
kirgrim Jul 18, 2022
b785ac8
Added STT and TTS response handling by observer
kirgrim Jul 20, 2022
96274c0
Cleaned up dependencies
kirgrim Jul 20, 2022
09aee26
Bidictionary for neon languages mapping
kirgrim Jul 20, 2022
2118bde
Added SFTP support
kirgrim Jul 20, 2022
3237a8f
Socket IO handlers for STT/TTS (TTS implementation)
kirgrim Jul 20, 2022
e70b09d
Fixed issue with uninitialized language selector while loading from l…
kirgrim Jul 21, 2022
5c9b7e6
Merge branch 'dev' into tts_support
kirgrim Jul 21, 2022
9b2bd1d
Add TTS UI
kirgrim Jul 22, 2022
05de4a7
Finished TTS flow
kirgrim Jul 22, 2022
b190bad
Added docstrings for new TTS methods
kirgrim Jul 22, 2022
7004205
Added record audio handler
kirgrim Jul 22, 2022
fef340d
Buffered-based TTS handling
kirgrim Jul 30, 2022
6ef532c
Added endpoint for streaming audio message
kirgrim Jul 30, 2022
23daa9d
Support for audio message fetching
kirgrim Jul 31, 2022
2d7e895
Fixed issues with audio messages
kirgrim Aug 4, 2022
fba9f39
Completed implementation of STT component
kirgrim Aug 7, 2022
6b01072
Fixed known issues from PR
kirgrim Aug 7, 2022
7bb4fd5
stub for SFTP properties
kirgrim Aug 7, 2022
e3fec6e
set recognizer as a default skill
kirgrim Aug 8, 2022
e042299
added license headers
kirgrim Aug 11, 2022
1fd4985
incremented requirement for neon-sftp
kirgrim Aug 11, 2022
d97de11
buffered audio strings handling
kirgrim Aug 11, 2022
4bcbeea
Refactored modules to handle neon responses from recognizer loop
kirgrim Aug 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions chat_client/blueprints/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,38 @@
from starlette.requests import Request
from starlette.templating import Jinja2Templates

from chat_client.client_config import app_config
from utils.template_utils import callback_template

router = APIRouter(
prefix="/components",
responses={'404': {"description": "Unknown endpoint"}},
)

component_templates = Jinja2Templates(directory=os.environ.get('TEMPLATES_DIR', "chat_client/templates"))

@router.get('/user_message')
async def render_user_message(request: Request, is_audio: bool = False, message_id: str = ''):
""" Handling requests for rendering user message HTML
:param request: Fast API request object
:param is_audio: is audio message (defaults to false)
:param message_id: id of the message to render (optional)"""
# fetching audio message template if required
template_context = {}
template_name = 'user_message'
if is_audio and message_id:
template_name = 'user_message_audio'
template_context['audio_url'] = f'{app_config["SERVER_URL"]}/files/get_audio/{message_id}'
return callback_template(request=request, template_name=template_name, context=template_context)


@router.get('/{template_name}')
async def chats(request: Request, template_name: str):
async def render_template(request: Request, template_name: str):
"""
Renders chats page HTML as a response related to the input request
Base renderer by the provided HTML template name

:param request: FastAPI request object
:param template_name: name of template to fetch

:returns chats conversation response
"""

return component_templates.TemplateResponse(f"components/{template_name}.html", {"request": request})
return callback_template(request=request, template_name=template_name)
74 changes: 52 additions & 22 deletions chat_client/static/css/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ body{
}

.chat-list li {
margin-bottom: 10px;
padding-bottom: 10px!important;
max-height: 250px!important;
overflow: auto;
color: #ffffff;
}
Expand Down Expand Up @@ -45,7 +46,7 @@ body{
display: inline-block;
padding: 10px 20px;
position: relative;
max-width: 100%!important;
max-width: 70%!important;
font-size: 14px!important;
}

Expand All @@ -55,14 +56,6 @@ body{
overflow-y: auto!important;
}

/*.chat-list .chat-message:before {*/
/* content: "";*/
/* position: absolute;*/
/* top: 15px;*/
/* width: 0;*/
/* height: 0;*/
/*}*/

.chat-list .chat-message h5 {
margin: 0 0 5px 0;
font-weight: 600;
Expand All @@ -81,11 +74,23 @@ body{
width: 70%;
}

/*.chat-list .in .chat-message:before {*/
/* left: -12px;*/
/* border-bottom: 20px solid transparent;*/
/* border-right: 20px solid #5a99ee;*/
/*}*/
.chat-message-actions {
height: 80px;
width: 25%!important;
/*background-color: black;*/
}

.icon-volume-up {
color: black;
}

.fa-lg {
font-size: 18px;
}

/*
Out message styling
*/

.chat-list .out .chat-img {
float: right;
Expand All @@ -97,19 +102,30 @@ body{
margin-right: 5px!important;
}

.chat-list .in .chat-body {
margin-left: 5px!important;
.chat-list .out .chat-message-actions {
float: right;
}

.chat-list .out .chat-message {
background: #fc6d4c;
float: right;
}

/*.chat-list .out .chat-message:before {*/
/* right: -12px;*/
/* border-bottom: 20px solid transparent;*/
/* border-left: 20px solid #fc6d4c;*/
/*}*/
/*
In message styling
*/

.chat-list .in .chat-body {
margin-left: 5px!important;
}

.chat-list .in .chat-message {
float: left;
}

.chat-list .in .chat-message-actions {
float: left;
}

.card .card-header:first-child {
-webkit-border-radius: 0.3rem 0.3rem 0 0;
Expand Down Expand Up @@ -260,4 +276,18 @@ body{
left: 35%;
top: 40%;
z-index: 999;
}

.message-audio {
max-height: 100%;
max-width: 100%;
margin: auto;
object-fit: contain;
}

.stt-content{
display: none;
overflow-y: auto;
max-height: 150px!important;
min-height: 25px!important;
}
9 changes: 5 additions & 4 deletions chat_client/static/js/builder_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ function fetchTemplateContext(html, templateContext){
* Builds HTML from passed params and template name
* @param templateName: name of the template to fetch
* @param templateContext: properties from template to fetch
* @param requestArgs: request string arguments (optional)
* @returns built template string
*/
async function buildHTMLFromTemplate(templateName, templateContext = {}){
if(!configData['DISABLE_CACHING'] && loadedComponents.hasOwnProperty(templateName)){
async function buildHTMLFromTemplate(templateName, templateContext = {}, requestArgs=''){
if(!configData['DISABLE_CACHING'] && loadedComponents.hasOwnProperty(templateName) && !requestArgs){
const html = loadedComponents[templateName];
return fetchTemplateContext(html, templateContext);
}else {
return await fetch(`${configData['currentURLBase']}/components/${templateName}`)
return await fetch(`${configData['currentURLBase']}/components/${templateName}?${requestArgs}`)
.then((response) => {
if (response.ok) {
return response.text();
}
throw `template unreachable (HTTP STATUS:${response.status}: ${response.statusText})`
})
.then((html) => {
if (!(configData['DISABLE_CACHING'] || loadedComponents.hasOwnProperty(templateName))) {
if (!(configData['DISABLE_CACHING'] || loadedComponents.hasOwnProperty(templateName) || requestArgs)) {
loadedComponents[templateName] = html;
}
return fetchTemplateContext(html, templateContext);
Expand Down
Loading