|
| 1 | +import React from 'react'; |
| 2 | +import { View, Text, StyleSheet } from 'react-native'; |
| 3 | +import { TranscriptionResult } from 'react-native-executorch'; |
| 4 | + |
| 5 | +export const VerboseTranscription = ({ |
| 6 | + data, |
| 7 | +}: { |
| 8 | + data: TranscriptionResult; |
| 9 | +}) => { |
| 10 | + if (!data) return null; |
| 11 | + |
| 12 | + const hasSegments = Array.isArray(data.segments) && data.segments.length > 0; |
| 13 | + |
| 14 | + const hasLanguage = |
| 15 | + !!data.language && data.language !== 'N/A' && data.language.trim() !== ''; |
| 16 | + |
| 17 | + const hasDuration = typeof data.duration === 'number' && data.duration > 0; |
| 18 | + |
| 19 | + const hasMetadata = hasLanguage || hasDuration; |
| 20 | + |
| 21 | + return ( |
| 22 | + <View style={styles.container}> |
| 23 | + <View style={styles.metaContainer}> |
| 24 | + <Text style={styles.label}>Full Text:</Text> |
| 25 | + <Text style={styles.text}>{data.text || ''}</Text> |
| 26 | + |
| 27 | + {hasMetadata && ( |
| 28 | + <View style={styles.row}> |
| 29 | + {hasLanguage && ( |
| 30 | + <Text style={styles.metaItem}>Language: {data.language}</Text> |
| 31 | + )} |
| 32 | + {hasDuration && ( |
| 33 | + <Text style={styles.metaItem}> |
| 34 | + Duration: {data.duration?.toFixed(2)}s |
| 35 | + </Text> |
| 36 | + )} |
| 37 | + </View> |
| 38 | + )} |
| 39 | + </View> |
| 40 | + |
| 41 | + {hasSegments && ( |
| 42 | + <> |
| 43 | + <Text style={styles.sectionHeader}> |
| 44 | + Segments ({data.segments?.length}) |
| 45 | + </Text> |
| 46 | + |
| 47 | + {data.segments?.map((seg, index) => ( |
| 48 | + <View key={index} style={styles.segmentCard}> |
| 49 | + <View style={styles.segmentHeader}> |
| 50 | + <Text style={styles.timeBadge}> |
| 51 | + {seg.start.toFixed(2)}s - {seg.end.toFixed(2)}s |
| 52 | + </Text> |
| 53 | + <Text style={styles.segmentId}>ID: {index}</Text> |
| 54 | + </View> |
| 55 | + |
| 56 | + <Text style={styles.segmentText}>"{seg.text}"</Text> |
| 57 | + |
| 58 | + {seg.words && seg.words.length > 0 && ( |
| 59 | + <View style={styles.wordsContainer}> |
| 60 | + <Text style={styles.statLabel}>Word Timestamps:</Text> |
| 61 | + <View style={styles.wordsGrid}> |
| 62 | + {seg.words.map((w, wIdx) => ( |
| 63 | + <View key={wIdx} style={styles.wordChip}> |
| 64 | + <Text style={styles.wordText}>{w.word.trim()}</Text> |
| 65 | + <Text style={styles.wordTime}> |
| 66 | + {w.start.toFixed(2)}s |
| 67 | + </Text> |
| 68 | + </View> |
| 69 | + ))} |
| 70 | + </View> |
| 71 | + </View> |
| 72 | + )} |
| 73 | + |
| 74 | + <View style={styles.statsGrid}> |
| 75 | + <View style={styles.statItem}> |
| 76 | + <Text style={styles.statLabel}>Avg LogProb</Text> |
| 77 | + <Text style={styles.statValue}> |
| 78 | + {data.task === 'transcribe' |
| 79 | + ? seg.avgLogprob?.toFixed(4) |
| 80 | + : 'N/A'} |
| 81 | + </Text> |
| 82 | + </View> |
| 83 | + <View style={styles.statItem}> |
| 84 | + <Text style={styles.statLabel}>Temp</Text> |
| 85 | + <Text style={styles.statValue}> |
| 86 | + {data.task === 'transcribe' |
| 87 | + ? seg.temperature?.toFixed(2) |
| 88 | + : 'N/A'} |
| 89 | + </Text> |
| 90 | + </View> |
| 91 | + <View style={styles.statItem}> |
| 92 | + {/*eslint-disable-next-line @cspell/spellchecker*/} |
| 93 | + <Text style={styles.statLabel}>Compr.</Text> |
| 94 | + <Text style={styles.statValue}> |
| 95 | + {data.task === 'transcribe' |
| 96 | + ? seg.compressionRatio?.toFixed(2) |
| 97 | + : 'N/A'} |
| 98 | + </Text> |
| 99 | + </View> |
| 100 | + </View> |
| 101 | + </View> |
| 102 | + ))} |
| 103 | + </> |
| 104 | + )} |
| 105 | + </View> |
| 106 | + ); |
| 107 | +}; |
| 108 | + |
| 109 | +const styles = StyleSheet.create({ |
| 110 | + container: { |
| 111 | + padding: 4, |
| 112 | + }, |
| 113 | + metaContainer: { |
| 114 | + marginBottom: 16, |
| 115 | + padding: 12, |
| 116 | + backgroundColor: '#f0f2f5', |
| 117 | + borderRadius: 8, |
| 118 | + }, |
| 119 | + label: { |
| 120 | + fontWeight: 'bold', |
| 121 | + color: '#0f186e', |
| 122 | + marginBottom: 4, |
| 123 | + }, |
| 124 | + text: { |
| 125 | + fontSize: 16, |
| 126 | + color: '#333', |
| 127 | + marginBottom: 8, |
| 128 | + }, |
| 129 | + row: { |
| 130 | + flexDirection: 'row', |
| 131 | + gap: 10, |
| 132 | + marginTop: 8, |
| 133 | + }, |
| 134 | + metaItem: { |
| 135 | + fontSize: 12, |
| 136 | + color: '#666', |
| 137 | + backgroundColor: '#e1e4e8', |
| 138 | + paddingHorizontal: 8, |
| 139 | + paddingVertical: 2, |
| 140 | + borderRadius: 4, |
| 141 | + overflow: 'hidden', |
| 142 | + }, |
| 143 | + sectionHeader: { |
| 144 | + fontSize: 18, |
| 145 | + fontWeight: 'bold', |
| 146 | + color: '#0f186e', |
| 147 | + marginBottom: 8, |
| 148 | + marginTop: 8, |
| 149 | + }, |
| 150 | + segmentCard: { |
| 151 | + backgroundColor: '#fff', |
| 152 | + borderRadius: 8, |
| 153 | + borderWidth: 1, |
| 154 | + borderColor: '#e1e4e8', |
| 155 | + marginBottom: 12, |
| 156 | + padding: 12, |
| 157 | + shadowColor: '#000', |
| 158 | + shadowOffset: { width: 0, height: 1 }, |
| 159 | + shadowOpacity: 0.1, |
| 160 | + shadowRadius: 2, |
| 161 | + elevation: 2, |
| 162 | + }, |
| 163 | + segmentHeader: { |
| 164 | + flexDirection: 'row', |
| 165 | + justifyContent: 'space-between', |
| 166 | + marginBottom: 8, |
| 167 | + }, |
| 168 | + timeBadge: { |
| 169 | + fontSize: 12, |
| 170 | + fontWeight: 'bold', |
| 171 | + color: '#fff', |
| 172 | + backgroundColor: '#0f186e', |
| 173 | + paddingHorizontal: 8, |
| 174 | + paddingVertical: 2, |
| 175 | + borderRadius: 12, |
| 176 | + overflow: 'hidden', |
| 177 | + }, |
| 178 | + segmentId: { |
| 179 | + fontSize: 12, |
| 180 | + color: '#888', |
| 181 | + }, |
| 182 | + segmentText: { |
| 183 | + fontSize: 15, |
| 184 | + fontStyle: 'italic', |
| 185 | + color: '#333', |
| 186 | + marginBottom: 12, |
| 187 | + }, |
| 188 | + statsGrid: { |
| 189 | + flexDirection: 'row', |
| 190 | + flexWrap: 'wrap', |
| 191 | + gap: 8, |
| 192 | + borderTopWidth: 1, |
| 193 | + borderTopColor: '#f0f0f0', |
| 194 | + paddingTop: 8, |
| 195 | + }, |
| 196 | + statItem: { |
| 197 | + flex: 1, |
| 198 | + minWidth: '45%', |
| 199 | + flexDirection: 'row', |
| 200 | + justifyContent: 'space-between', |
| 201 | + }, |
| 202 | + statLabel: { |
| 203 | + fontSize: 11, |
| 204 | + color: '#888', |
| 205 | + }, |
| 206 | + statValue: { |
| 207 | + fontSize: 11, |
| 208 | + fontWeight: '600', |
| 209 | + color: '#444', |
| 210 | + }, |
| 211 | + wordsContainer: { |
| 212 | + marginVertical: 8, |
| 213 | + backgroundColor: '#f8f9fa', |
| 214 | + padding: 8, |
| 215 | + borderRadius: 6, |
| 216 | + }, |
| 217 | + wordsGrid: { |
| 218 | + flexDirection: 'row', |
| 219 | + flexWrap: 'wrap', |
| 220 | + gap: 6, |
| 221 | + marginTop: 4, |
| 222 | + }, |
| 223 | + wordChip: { |
| 224 | + backgroundColor: '#ffffff', |
| 225 | + borderWidth: 1, |
| 226 | + borderColor: '#e1e4e8', |
| 227 | + borderRadius: 4, |
| 228 | + paddingHorizontal: 6, |
| 229 | + paddingVertical: 2, |
| 230 | + alignItems: 'center', |
| 231 | + }, |
| 232 | + wordText: { |
| 233 | + fontSize: 12, |
| 234 | + color: '#333', |
| 235 | + }, |
| 236 | + wordTime: { |
| 237 | + fontSize: 9, |
| 238 | + color: '#888', |
| 239 | + marginTop: 1, |
| 240 | + }, |
| 241 | +}); |
0 commit comments