add text response interface
This commit is contained in:
parent
7a09fd6f0f
commit
763026d59f
|
@ -5,6 +5,7 @@ import {
|
||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
BackHandler,
|
BackHandler,
|
||||||
|
ScrollView,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import * as FileSystem from "expo-file-system";
|
import * as FileSystem from "expo-file-system";
|
||||||
import { Audio } from "expo-av";
|
import { Audio } from "expo-av";
|
||||||
|
@ -52,6 +53,8 @@ const Main: React.FC<MainProps> = ({ route }) => {
|
||||||
inputRange: [0, 1],
|
inputRange: [0, 1],
|
||||||
outputRange: ["white", "black"],
|
outputRange: ["white", "black"],
|
||||||
});
|
});
|
||||||
|
const [accumulatedMessage, setAccumulatedMessage] = useState<string>("");
|
||||||
|
const scrollViewRef = useRef<ScrollView>(null);
|
||||||
|
|
||||||
const constructTempFilePath = async (buffer: string) => {
|
const constructTempFilePath = async (buffer: string) => {
|
||||||
try {
|
try {
|
||||||
|
@ -151,6 +154,10 @@ const Main: React.FC<MainProps> = ({ route }) => {
|
||||||
websocket.onmessage = async (e) => {
|
websocket.onmessage = async (e) => {
|
||||||
try {
|
try {
|
||||||
const message = JSON.parse(e.data);
|
const message = JSON.parse(e.data);
|
||||||
|
if (message.content && message.type == "message" && message.role == "assistant"){
|
||||||
|
setAccumulatedMessage((prevMessage) => prevMessage + message.content);
|
||||||
|
scrollViewRef.current?.scrollToEnd({ animated: true });
|
||||||
|
}
|
||||||
|
|
||||||
if (message.content && message.type == "audio") {
|
if (message.content && message.type == "audio") {
|
||||||
const buffer = message.content;
|
const buffer = message.content;
|
||||||
|
@ -198,7 +205,18 @@ const Main: React.FC<MainProps> = ({ route }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Animated.View style={[styles.container, { backgroundColor }]}>
|
<Animated.View style={[styles.container, { backgroundColor }]}>
|
||||||
<View style={styles.middle}>
|
<View style={{flex: 6, alignItems: "center", justifyContent: "center",}}>
|
||||||
|
<ScrollView
|
||||||
|
ref={scrollViewRef}
|
||||||
|
style={styles.scrollViewContent}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
>
|
||||||
|
<Text style={styles.accumulatedMessage}>
|
||||||
|
{accumulatedMessage}
|
||||||
|
</Text>
|
||||||
|
</ScrollView>
|
||||||
|
</View>
|
||||||
|
<View style={{flex: 2, justifyContent: "center", alignItems: "center",}}>
|
||||||
<RecordButton
|
<RecordButton
|
||||||
playPip={playPip}
|
playPip={playPip}
|
||||||
playPop={playPop}
|
playPop={playPop}
|
||||||
|
@ -211,6 +229,8 @@ const Main: React.FC<MainProps> = ({ route }) => {
|
||||||
buttonBackgroundColor={buttonBackgroundColor}
|
buttonBackgroundColor={buttonBackgroundColor}
|
||||||
setIsPressed={setIsPressed}
|
setIsPressed={setIsPressed}
|
||||||
/>
|
/>
|
||||||
|
</View>
|
||||||
|
<View style={{flex: 1}}>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={styles.statusButton}
|
style={styles.statusButton}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
|
@ -238,39 +258,7 @@ const Main: React.FC<MainProps> = ({ route }) => {
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
position: "relative",
|
|
||||||
},
|
},
|
||||||
middle: {
|
|
||||||
flex: 1,
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
padding: 10,
|
|
||||||
position: "relative",
|
|
||||||
},
|
|
||||||
circle: {
|
|
||||||
width: 100,
|
|
||||||
height: 100,
|
|
||||||
borderRadius: 50,
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
},
|
|
||||||
qr: {
|
|
||||||
position: "absolute",
|
|
||||||
top: 30,
|
|
||||||
left: 10,
|
|
||||||
padding: 10,
|
|
||||||
zIndex: 100,
|
|
||||||
},
|
|
||||||
icon: {
|
|
||||||
height: 40,
|
|
||||||
width: 40,
|
|
||||||
},
|
|
||||||
topBar: {
|
|
||||||
height: 40,
|
|
||||||
backgroundColor: "#000",
|
|
||||||
paddingTop: 50,
|
|
||||||
},
|
|
||||||
|
|
||||||
statusText: {
|
statusText: {
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
|
@ -280,6 +268,21 @@ const styles = StyleSheet.create({
|
||||||
bottom: 20,
|
bottom: 20,
|
||||||
alignSelf: "center",
|
alignSelf: "center",
|
||||||
},
|
},
|
||||||
|
accumulatedMessage: {
|
||||||
|
margin: 20,
|
||||||
|
fontSize: 16,
|
||||||
|
textAlign: "left",
|
||||||
|
color: "white",
|
||||||
|
paddingBottom: 30,
|
||||||
|
},
|
||||||
|
scrollViewContent: {
|
||||||
|
padding: 25,
|
||||||
|
width: "90%",
|
||||||
|
maxHeight: "80%",
|
||||||
|
borderWidth: 5,
|
||||||
|
borderColor: "white",
|
||||||
|
borderRadius: 10,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default Main;
|
export default Main;
|
||||||
|
|
Loading…
Reference in New Issue