Commit 6f188f32 authored by Tharuka Dilshan's avatar Tharuka Dilshan

Merge branch 'Dilshan-P.G.T-DEV' into master2

parents 6054d0e0 3287c25c
This diff is collapsed.
import React, { useState } from 'react';
import axios from 'axios';
import { useRecordWebcam } from 'react-record-webcam';
import RestService from "../services/RestService";
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) => {
const selectedFile = event.target.files[0];
setFile(selectedFile);
};
// const handleUpload = () => {
// if (file) {
// try {
// const formData = new FormData();
// formData.append('audio1', file);
// axios.post('http://127.0.0.1:5000/uploadaudio', formData, {
// //axios.get('http://localhost:9000/', formData, {
// headers: {
// 'Content-Type': 'multipart/form-data',
// },
// });
// console.log('File uploaded successfully!');
// } catch (error) {
// console.error('Error uploading file:', error);
// }
// }
// };
//*************************************************** */
const [videoFile, setVideoFile] = useState(null);
const [audioFile, setAudioFile] = useState([]);
const handleVideoFileChange = (event) => {
setVideoFile(event.target.files[0]);
};
const handleAudioFileChange = (event) => {
setAudioFile(event.target.files[0]);
};
const handleVideoUpload = () => {
if (videoFile) {
const formData = new FormData();
formData.append('video', videoFile);
axios.post('http://127.0.0.1:5000/transcribe-audio', formData)
.then(response => {
console.log('Video uploaded successfully');
})
.catch(error => {
console.error('Error:', error);
});
}
};
const handleAudioUpload = () => {
console.log(audioFile)
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);
})
// 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);
// });
};
return (
<div className="col col-lg-12">
<div className='row'>
<h1>Upload Video</h1>
</div>
<div className='row'>
<input type="file" accept="video/*" onChange={handleVideoFileChange} />
{/* <button onClick={handleVideoUpload}>Upload Video</button> */}
<button className="btn video-btn" onClick={handleVideoUpload}>Upload Video</button>
</div>
<div className='row'>
<h1>Upload Audio</h1>
</div>
<div className='row'>
<input type="file" onChange={(e)=>setAudioFile(e.target.files[0])} />
{/* <button onClick={handleAudioUpload}>Upload Audio</button> */}
<button className="btn video-btn" onClick={handleAudioUpload}>Upload Audio</button>
</div>
<br/>
<div className="row">
<div className="col-6 col-sm-4">
<h3 className="mt-4" style={{fontFamily:'FMAbayaBld'}}>w¾:h ( </h3>
<h1 className="d-flex align-items-center justify-content-center" >ffffs</h1>
</div>
<div class="col-6 col-sm-4">
<video autoPlay muted className="video-box1"/>
</div>
</div>
</div>
);
};
export default AudioToSign;
......@@ -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