Commit de86a677 authored by Malsha Rathnasiri's avatar Malsha Rathnasiri

tts part

parent b733b112
import React, { createContext, useContext, useState, useEffect, useLayoutEffect } from "react";
import { nexlAxios } from "../../constants/helper";
import AsyncStorage from "@react-native-community/async-storage";
import {
IAuthContext,
IAuthRequest,
STORAGE_BEARER_TOKEN,
UNINITIALISED,
USER_EMAIL,
} from "./IAuthContext";
import { Loading } from "./state/Loading";
import { getEnvironment } from "../../constants/variables";
import { AxiosError, AxiosResponse } from "axios";
import { rollbar } from "./ErrorBoundary";
const AuthContext = createContext({
isLoggedIn: false,
token: "",
email: "",
error: "",
loading: false,
initialised: false,
login: UNINITIALISED,
logout: UNINITIALISED,
});
export const useAuthContext = () => useContext(AuthContext);
export const AuthConsumer = AuthContext.Consumer;
// interface IProps {
// children: any;
// }
// interface ILoginData {
// error: string;
// user: {
// email: string;
// id: string;
// first_name: string;
// last_name: string;
// };
// }
const endpoint = getEnvironment().endpoint;
export const AuthProvider= ({ children }) => {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [token, setToken] = useState("");
const [email, setEmail] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [initialised, setInitialised] = useState(false);
const login = async ({ email, password, rememberMe }) => {
setLoading(true);
nexlAxios(false)
.post(`${endpoint}/accounts/sign_in.json`, {
source: "iOS app",
account: {
email,
password,
remember_me: rememberMe ? "1" : "0",
},
})
.then(async (response) => {
setLoading(false);
const user = response.data.user;
user.email && setIsLoggedIn(true);
const token = response.headers["authorization"];
setToken(token);
await AsyncStorage.setItem(USER_EMAIL, email);
setEmail(email);
rollbar.setPerson(user.id, `${user.first_name} ${user.last_name}`, user.email);
})
.catch((result) => {
setLoading(false);
setError(
result?.response?.data?.error || result?.message || "An unknown error has occurred.",
);
});
};
const loginWithBearerToken = async (bearer) => {
if (bearer) {
setLoading(true);
await nexlAxios(false, bearer)
.post(`${endpoint}/accounts/sign_in.json`, undefined, {
headers: {
Authorization: bearer,
},
})
.then((response) => {
setLoading(false);
const user = response.data.user;
user.email && setIsLoggedIn(true);
rollbar.setPerson(user.id, `${user.first_name} ${user.last_name}`, user.email);
})
.catch(() => {
setLoading(false);
setToken("");
});
}
};
const logout = async () => {
const token = await AsyncStorage.getItem(STORAGE_BEARER_TOKEN);
token && (await nexlAxios(false, token).post(`${endpoint}/sign_out.json`));
setToken("");
setIsLoggedIn(false);
await AsyncStorage.removeItem(STORAGE_BEARER_TOKEN);
rollbar.clearPerson();
};
// look if token / email exist in local storage on initialising the app
// if token exists, try log in with token
useLayoutEffect(() => {
let isMounted = true;
const initialise = async () => {
const bearerToken = await AsyncStorage.getItem(STORAGE_BEARER_TOKEN);
setToken(bearerToken || "");
const userEmail = await AsyncStorage.getItem(USER_EMAIL);
setEmail(userEmail || "");
bearerToken && (await loginWithBearerToken(bearerToken));
setInitialised(true);
};
if (isMounted) {
initialise();
}
return () => {
isMounted = false;
};
}, []);
// update token to local storage on token change
useEffect(() => {
AsyncStorage.setItem(STORAGE_BEARER_TOKEN, token);
}, [token]);
return (
<AuthContext.Provider
value={{
login,
isLoggedIn,
logout,
token,
email: email.toLowerCase(),
loading,
error,
initialised,
}}
>
{initialised ? children : <Loading copy="Logging in..." />}
</AuthContext.Provider>
);
};
\ No newline at end of file
import React from 'react'
import { Text, View, StyleSheet, Button } from 'react-native';
import { Audio } from 'expo-av';
import { createIconSetFromFontello } from '@expo/vector-icons';
import * as FileSystem from 'expo-file-system';
export const AudioRecorder = ({ setDetectedText }) => {
const [recording, setRecording] = React.useState();
const [sound, setSound] = React.useState();
async function startRecording() {
try {
console.log('Requesting permissions..');
await Audio.requestPermissionsAsync();
await Audio.setAudioModeAsync({
allowsRecordingIOS: true,
playsInSilentModeIOS: true,
});
console.log('Starting recording..');
const { recording } = await Audio.Recording.createAsync(
Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY
);
setRecording(recording);
console.log('Recording started');
} catch (err) {
console.error('Failed to start recording', err);
}
}
async function stopRecording() {
console.log('Stopping recording..');
setRecording(undefined);
await recording.stopAndUnloadAsync();
const uri = recording.getURI();
console.log('Recording stopped and stored at', uri);
console.log(recording)
const headers = {
'Content-Type': 'multipart/form-data'
// 'Content-Type': 'application/x-www-form-urlencoded',
}
playSound(uri)
FileSystem.uploadAsync("https://1ec4-112-134-210-155.ap.ngrok.io/mlmodels/detect/", uri, { headers: headers, uploadType: FileSystem.FileSystemUploadType.MULTIPART })
.then(data => JSON.parse(data.body))
.then(data => { console.log({ result: data }); setDetectedText(data.result); setTimeout(() => setDetectedText(''), 1000) })
.catch(err => console.log({ err }))
}
async function playSound(uri) {
console.log('Loading Sound');
// const { sound } = await Audio.Sound.createAsync(
// require(uri)
// );
// setSound(sound);
// console.log('Playing Sound');
// await sound.playAsync();
}
return (
<Button
style={{ height: '100%', padding: 5 }}
title={recording ? 'Stop Recording' : 'Start Recording'}
onPress={recording ? stopRecording : startRecording}
/>
);
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import { ColorSchemeName, Pressable } from 'react-native';
import Colors from '../constants/Colors';
import useColorScheme from '../hooks/useColorScheme';
import { LoginScreen } from '../screens/loginScreen';
import ModalScreen from '../screens/ModalScreen';
import NotFoundScreen from '../screens/NotFoundScreen';
import TabOneScreen from '../screens/TabOneScreen';
......@@ -36,10 +37,28 @@ export default function Navigation({ colorScheme }: { colorScheme: ColorSchemeNa
const Stack = createNativeStackNavigator<RootStackParamList>();
function RootNavigator() {
const [isAuthenticated, setIsAutheticated] = React.useState(false)
const onLogin = () => {
setIsAutheticated(true)
}
const onLogout = () => {
setIsAutheticated(false)
}
return (
<Stack.Navigator>
<Stack.Screen name="Root" component={BottomTabNavigator} options={{ headerShown: false }} />
<Stack.Navigator >
{isAuthenticated ? <Stack.Screen name="Root" options={{ headerShown: false }}>{(props) => <BottomTabNavigator {...props} onLogout={onLogout}/>}</Stack.Screen> :
<Stack.Screen name='Login'>{(props) => <LoginScreen {...props} onLogin={onLogin} />}</Stack.Screen>}
<Stack.Screen name="NotFound" component={NotFoundScreen} options={{ title: 'Oops!' }} />
<Stack.Group screenOptions={{ presentation: 'modal' }}>
<Stack.Screen name="Modal" component={ModalScreen} />
</Stack.Group>
......@@ -53,7 +72,7 @@ function RootNavigator() {
*/
const BottomTab = createBottomTabNavigator<RootTabParamList>();
function BottomTabNavigator() {
function BottomTabNavigator({onLogout}) {
const colorScheme = useColorScheme();
return (
......@@ -66,11 +85,12 @@ function BottomTabNavigator() {
name="TabOne"
component={TabOneScreen}
options={({ navigation }: RootTabScreenProps<'TabOne'>) => ({
title: 'Tab One',
title: 'Chat',
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
headerRight: () => (
<Pressable
onPress={() => navigation.navigate('Modal')}
// onPress={() => navigation.navigate('Modal')}
onPress={onLogout}
style={({ pressed }) => ({
opacity: pressed ? 0.5 : 1,
})}>
......
......@@ -18,14 +18,19 @@
"@react-navigation/bottom-tabs": "^6.0.5",
"@react-navigation/native": "^6.0.2",
"@react-navigation/native-stack": "^6.1.0",
"axios": "^0.27.2",
"expo": "~44.0.0",
"expo-asset": "~8.4.4",
"expo-av": "~10.2.0",
"expo-constants": "~13.0.0",
"expo-file-system": "~13.1.4",
"expo-font": "~10.0.4",
"expo-linking": "~3.0.0",
"expo-media-library": "~14.0.0",
"expo-splash-screen": "~0.14.0",
"expo-status-bar": "~1.2.0",
"expo-web-browser": "~10.1.0",
"jwt-decode": "^3.1.2",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
......@@ -37,8 +42,8 @@
"@babel/core": "^7.12.9",
"@types/react": "~17.0.21",
"@types/react-native": "~0.64.12",
"jest-expo": "~44.0.1",
"jest": "^26.6.3",
"jest-expo": "~44.0.1",
"react-test-renderer": "17.0.1",
"typescript": "~4.3.5"
},
......
import React, { useState } from 'react'
import { StyleSheet, TextInput } from 'react-native';
import { AudioRecorder } from '../components/AudioRecorder';
import EditScreenInfo from '../components/EditScreenInfo';
import { Text, View } from '../components/Themed';
import { RootTabScreenProps } from '../types';
export default function TabOneScreen({ navigation }: RootTabScreenProps<'TabOne'>) {
const [detectedText, setDetectedText] = useState("")
return (
<View style={styles.container}>
<Text style={styles.title}>Tab One</Text>
<View style={{height: 70, width: 100, backgroundColor: ''}}><TextInput style={{height: 100, width: 1000, }} onChange={() => console.log('change')}></TextInput></View>
{/* <Text style={styles.title}>Tab One</Text>
<View style={{height: 70, width: 100, backgroundColor: ''}}><TextInput style={{borderColor: 'white', borderWidth: 1, alignSelf: }} onChange={() => console.log('change')}></TextInput></View>
<View style={styles.separator} lightColor="#000" darkColor="rgba(255,0,255,0.1)" />
<EditScreenInfo path="/screens/TabOneScreen.tsx" />
<EditScreenInfo path="/screens/TabOneScreen.tsx" /> */}
<View style={{ flex: 1, width: '100%' }}>
<View style={{ display: 'flex', flex: 0.9, backgroundColor: 'green' }}>
<View style={{ alignItems: 'center', justifyContent: 'center', height: '100%'}}><Text style={{fontSize: 50, color: 'white'}}>{detectedText}</Text></View>
</View>
<View style={{ flex: 0.1, backgroundColor: 'rgb(10,10,10)'}}>
<View style={{ flexDirection: 'row', display: 'flex', height: '100%' }}>
<View style={{ flex: 0.8, backgroundColor: 'rgb(10,10,10)', height: '100%' }}></View>
<View style={{ flex: 0.2, backgroundColor: 'rgb(10,10,10)', height:'100%'}}><AudioRecorder setDetectedText={setDetectedText} /></View>
</View>
</View>
</View>
</View>
);
}
......
......@@ -6,9 +6,7 @@ import { Text, View } from '../components/Themed';
export default function TabTwoScreen() {
return (
<View style={styles.container}>
<Text style={styles.title}>Tab Two</Text>
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
<EditScreenInfo path="/screens/TabTwoScreen.tsx" />
</View>
);
}
......
import React from 'react'
import { StyleSheet, TextInput} from 'react-native';
import EditScreenInfo from '../components/EditScreenInfo';
import { Text, View } from '../components/Themed';
import { TouchableOpacity } from 'react-native';
const LoginForm = ({onLogin}) => {
var passwordInput
return (
<>
<TextInput style={styles.input}
autoCapitalize="none"
// onSubmitEditing={() => passwordInput.focus()}
autoCorrect={false}
keyboardType='email-address'
returnKeyType="next"
placeholder='Email'
placeholderTextColor='rgba(225,225,225,0.7)' />
<TextInput style={styles.input}
returnKeyType="go"
ref={(input) => passwordInput = input}
placeholder='Password'
placeholderTextColor='rgba(225,225,225,0.7)'
secureTextEntry />
<TouchableOpacity style={styles.buttonContainer}
// onPress={onButtonPress}
onPress={onLogin}
>
<Text style={styles.buttonText}>LOGIN</Text>
</TouchableOpacity>
</>
// define your styles
)
}
export const LoginScreen = ({onLogin}) => {
return (
<View style={styles.container}>
<View style={styles.loginContainer}>
{/* r<Image resizeMode="contain" style={styles.logo} source={require('../../components/images/logo-dark-bg.png')} /> */}
</View>
<View style={styles.formContainer}>
<LoginForm onLogin={onLogin}/>
</View>
</View>
);
}
// define your styles
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#2c3e50',
},
loginContainer: {
alignItems: 'center',
flexGrow: 1,
justifyContent: 'center'
},
logo: {
position: 'absolute',
width: 300,
height: 100
},
container: {
padding: 20
},
input: {
height: 40,
backgroundColor: 'rgba(225,225,225,0.2)',
marginBottom: 10,
padding: 10,
color: '#fff'
},
buttonContainer: {
backgroundColor: '#2980b6',
paddingVertical: 15
},
buttonText: {
color: '#fff',
textAlign: 'center',
fontWeight: '700'
}
})
\ No newline at end of file
......@@ -16,6 +16,7 @@ declare global {
export type RootStackParamList = {
Root: NavigatorScreenParams<RootTabParamList> | undefined;
Modal: undefined;
Login: undefined;
NotFound: undefined;
};
......
This diff is collapsed.
Main objective:- Is to ensure that the passengers who are using public staff transport (Bus) are safe with covid and they are given the service according the government health regulations.
Main Research questions: How to deliver a safe public transport during the pandemic?
How to Ensure Passenger's health is safe?
How to build trust and motivate passengers to use Public Transport?
Individual research question
IT18145380 - How to select the perfect seat based on passenger attributes?
IT19012384 - How to manage real time tracking with the real time data?
How to do the payments through QR code with the public transportation?
IT18094664 - Interfaces to perform in-vehicle tasks while driving?
voice or manual interfaces?
IT19153728 - How to confirm the arrival of the relevant passenger and calculate the monthly fare based on the arrival of the passenger?
Individual Objectives,
IT18145380 - Provide a comfortable ride for the passenger
IT19012384 - To be able to use the time effectively with the help of route tracking.
To decrease the use of paper and cash usage by using QR payment method.
To facilitate daily activities in transportation.
IT18094664 - The main objective of this proposed research is to develop an application for the prevention of driver-related accidents and to make driver and passenger communication more efficient and convenient.
IT19153728 - The main objective of this research is marking the passenger's arrival and identify the passenger.
Main objective:- Is to ensure that the passengers who are using public staff transport (Bus) are safe with covid and they are given the service according the government health regulations.
Main Research questions: How to deliver a safe public transport during the pandemic?
How to Ensure Passenger's health is safe?
How to build trust and motivate passengers to use Public Transport?
Individual research question
IT18145380 - How to select the perfect seat based on passenger attributes?
IT19012384 - How to manage real time tracking with the real time data?
How to do the payments through QR code with the public transportation?
IT18094664 - Interfaces to perform in-vehicle tasks while driving?
voice or manual interfaces?
IT19153728 - How to confirm the arrival of the relevant passenger and calculate the monthly fare based on the arrival of the passenger?
Individual Objectives,
IT18145380 - Provide a comfortable ride for the passenger
IT19012384 - To be able to use the time effectively with the help of route tracking.
To decrease the use of paper and cash usage by using QR payment method.
To facilitate daily activities in transportation.
IT18094664 - The main objective of this proposed research is to develop an application for the prevention of driver-related accidents and to make driver and passenger communication more efficient and convenient.
IT19153728 - The main objective of this research is marking the passenger's arrival and identify the passenger.
backend/data/
backend/data/
*.pyc
\ No newline at end of file
"""
ASGI config for backend project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
application = get_asgi_application()
"""
ASGI config for backend project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
application = get_asgi_application()
from django.contrib import admin
# Register your models here.
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class CmsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'backend.cms'
from django.apps import AppConfig
class CmsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'backend.cms'
# Generated by Django 4.0.4 on 2022-04-25 19:51
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='MlModel',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('description', models.TextField(blank=True)),
('timestamp', models.DateTimeField(auto_now=True)),
('details', models.JSONField()),
],
),
]
# Generated by Django 4.0.4 on 2022-04-25 19:51
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='MlModel',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('description', models.TextField(blank=True)),
('timestamp', models.DateTimeField(auto_now=True)),
('details', models.JSONField()),
],
),
]
import pickle
from keras.models import load_model
import numpy as np
import IPython.display as ipd
import random
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
def predict():
model=load_model(r'./best_model_final.hdf5')
f1 = open('all_label.txt', 'rb')
all_label = pickle.load(f1)
print('loaded labels')
f2 = open('all_waves_file.txt', 'rb')
all_wave = pickle.load(f2)
print('loaded waves')
le = LabelEncoder()
y = le.fit_transform(all_label)
classes = list(le.classes_)
train_data_file = open("train_data_file.txt", 'rb')
[x_tr, x_val, y_tr, y_val] = np.load(train_data_file, allow_pickle=True)
train_data_file.close()
def predictSamples(audio):
prob=model.predict(audio.reshape(1,8000,1))
index=np.argmax(prob[0])
return classes[index]
index=random.randint(0,len(x_val)-1)
samples=x_val[index].ravel()
print("Audio:",classes[np.argmax(y_val[index])])
ipd.Audio(samples, rate=8000)