-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
88 lines (75 loc) · 2.33 KB
/
Copy pathApp.js
File metadata and controls
88 lines (75 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { View } from 'react-native';
import Camera from './components/Camera/Camera';
import AudioPlayer from './components/AudioPlayer/AudioPlayer';
import BookReader from './components/Camera/BookReader';
import ApiService from './services/ApiService';
import { decode as atob, encode as btoa } from 'base-64';
const Tab = createBottomTabNavigator();
function CameraAudioScreen() {
const [capturedImage, setCapturedImage] = React.useState(null);
const [audioFile, setAudioFile] = React.useState(null);
const handleImageCapture = (image) => {
console.log("app", image);
setCapturedImage(image);
};
const handleAudioReceived = (audio) => {
setAudioFile(audio);
};
React.useEffect(() => {
const fetchAudioFromApi = async () => {
try {
if (capturedImage) {
await ApiService.sendImage(capturedImage);
}
} catch (error) {
console.error('Error fetching audio:', error);
}
};
fetchAudioFromApi();
}, [capturedImage]);
return (
<View style={{ flex: 1 }}>
<Camera onImageCapture={handleImageCapture} />
<AudioPlayer audioFile={audioFile} />
</View>
);
}
function BookReaderAudioScreen() {
const [capturedBook, setCapturedBook] = React.useState(null);
const [audioFile, setAudioFile] = React.useState(null);
const handleBookReader = (image) => {
console.log("app", image);
setCapturedBook(image);
};
React.useEffect(() => {
const fetchAudioFromApiBookReader = async () => {
try {
if (capturedBook) {
await ApiService.sendReader(capturedBook);
}
} catch (error) {
console.error('Error fetching audio:', error);
}
};
fetchAudioFromApiBookReader();
}, [capturedBook]);
return (
<View style={{ flex: 1 }}>
<BookReader onBookReader={handleBookReader} />
<AudioPlayer audioFile={audioFile} />
</View>
);
}
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Camera" component={CameraAudioScreen} />
<Tab.Screen name="BookReader" component={BookReaderAudioScreen} />
</Tab.Navigator>
</NavigationContainer>
);
}