Commit 153c6b3f authored by Shashika Idushan's avatar Shashika Idushan

Merge branch 'master' into 'Madhushan-K.L.B-DEV'

# Conflicts:
#   Frontend/src/App.js
parents 46965ac8 bd2dcd81
This diff is collapsed.
......@@ -31,7 +31,7 @@ function SideNavBar() {
{/* සංඥා ශබ්දකෝෂය */}
<NavLink exact to="/about" className="nav-link main-nav-link" activeClassName="active-link">ix&#123;d YíofldaIh</NavLink>
{/* ශබ්ද පරිවර්ථකය */}
<NavLink exact to="/audio-to-sign" className="nav-link main-nav-link" activeClassName="active-link">Yío mßj¾:lh</NavLink>
<NavLink exact to="/contact" className="nav-link main-nav-link" activeClassName="active-link">Yío mßj¾:lh</NavLink>
{/* සංඥා හඳුනාගැනීම */}
<NavLink exact to="/sign-detection" className="nav-link main-nav-link " activeClassName="active-link">ix&#123;d y÷kd.ekSu</NavLink>
{/* වාචික පුහුණුව */}
......
......@@ -7,6 +7,12 @@ import '../styles/audioToSign.css';
const AudioToSign = () => {
const[isLogged, setIsLogged] = useState(sessionStorage.getItem("isLogged"));
const[token, setToken] = useState(sessionStorage.getItem("token"));
const[username, setUserName] = useState(sessionStorage.getItem("username"));
const[userId, setUserId] = useState(sessionStorage.getItem("userId"));
const [file, setFile] = useState(null);
const handleFileChange = (event) => {
......@@ -80,17 +86,26 @@ const AudioToSign = () => {
const handleAudioUpload = () => {
console.log(audioFile)
const formData = new FormData();
formData.append('audio1', audioFile);
axios.post('http://127.0.0.1:5000/transcribe-audio', formData)
.then(response => {
console.log(response);
console.log('Audio uploaded successfully');
const fileData = new FormData();
// formData.append('audio1', audioFile);
fileData.append('file', audioFile);
RestService.audioToSing(token,fileData).then((res)=>{
// setMeaning(res.data.signMap.value);
console.log(res);
}).catch((err)=>{
console.log(err);
})
.catch(error => {
console.error('Error:', error);
});
// axios.post('http://127.0.0.1:5000/transcribe-audio', formData)
// .then(response => {
// console.log(response);
// console.log('Audio uploaded successfully');
// })
// .catch(error => {
// console.error('Error:', error);
// });
};
......
.video-box1 {
border-width: 3px;
border-color:#af2c00;
border-style: solid;
border-radius: 2vw;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.552), 0 10px 10px 0 rgba(0, 0, 0, 0.338);
/* box-shadow: 0 1px 10px 0 rgba(66, 66, 66, 0.336), 0 6px 20px 0 rgba(100, 100, 100, 0.082); */
/* width: 40vw; */
height: 45vh;
width: 65vh;
align-items: center;
background-color: black;
background-image: url('../images/Skulls.jpg');
}
.aa {
align-items: end;
}
.card {
align-items: end;
width: 100%;
background-color: transparent;
border-color: transparent;
}
section {
margin: 20px;
}
input::-webkit-file-upload-button {
position: absolute;
padding: 6px 15px;
background-color: rgb(230, 154, 78);
border: none;
border-radius: 5px;
color: white;
text-transform: uppercase;
box-shadow: 0px 3px 3px -2px rgba(0,0,0,0.2), 0px 3px 4px 0px rgba(0,0,0,0.14), 0px 1px 8px 0px rgba(0,0,0,0.12);
transition: 100ms ease-out;
cursor: pointer;
}
input::-webkit-file-upload-button:hover {
background-color: #9e8160;
box-shadow: 0px 3px 5px -1px rgba(0,0,0,0.2), 0px 5px 8px 0px rgba(0,0,0,0.14), 0px 1px 14px 0px rgba(0,0,0,0.12)
}
\ No newline at end of file
......@@ -45,6 +45,13 @@ public class ShrasthraBackendController {
return responseDto;
}
@RequestMapping(value = REST_CONTROLLER_URL.AUDIO_TO_SIGN, method = RequestMethod.POST)
public @ResponseBody ProcessResponseDto audioToSign(@RequestParam("file") MultipartFile file, HttpServletRequest request){
ProcessResponseDto responseDto = new ProcessResponseDto();
responseDto = backendService.audioToSign(file);
return responseDto;
}
......
......@@ -8,5 +8,7 @@ import shrasthra.backend.dao.dto.ProcessResponseDto;
public interface ShrasthraBackendService {
public ProcessResponseDto detectDynamicSign(MultipartFile file);
public ProcessResponseDto audioToSign(MultipartFile file);
}
......@@ -101,4 +101,61 @@ public class ShrasthraBackendServiceImpl implements ShrasthraBackendService{
return responseDto;
}
public ProcessResponseDto audioToSign(MultipartFile file) {
ProcessResponseDto responseDto = new ProcessResponseDto();
try {
if (!file.isEmpty()) {
// Convert the file to bytes
byte[] fileBytes = file.getBytes();
RestTemplate restTemplate = new RestTemplate();
// Set the URL of your Python Flask API
String url = "http://127.0.0.1:5000/transcribe-audio";
// Create headers and set content type as multipart/form-data
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
// Create the request body with the file as a part
MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>();
requestBody.add("fileData", new ByteArrayResource(fileBytes) {
@Override
public String getFilename() {
return file.getOriginalFilename();
}
});
// Create the request entity with headers and body
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);
// Make the POST request to the second API
ResponseEntity<ProcessResponseDto> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity,
ProcessResponseDto.class);
// Retrieve the response body
ProcessResponseDto responseBody = response.getBody();
// Print the response
if(responseBody.getSign() != null) {
SignMap signMap = signMapRepository.findSignMapByLabel(responseBody.getSign());
if(signMap != null) {
responseDto.setSignMap(signMap);
responseDto.setSuccess(true);
}
}
}
} catch (Exception e) {
responseDto.setSuccess(false);
System.out.println("detectDynamicSign : " + e);
}
return responseDto;
}
}
......@@ -7,4 +7,6 @@ public class REST_CONTROLLER_URL {
public static final String DETECT_DYNAMIC_SIGN = "/sign/detectDynamicSign";
public static final String AUDIO_TO_SIGN = "/sign/audioToSign";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment