MCPcopy Create free account
hub / github.com/cactus-compute/cactus-react-native / STTScreen

Function STTScreen

example/src/STTScreen.tsx:18–241  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16import * as RNFS from '@dr.pogodin/react-native-fs';
17
18const STTScreen = () => {
19 const cactusSTT = useCactusSTT({ model: 'whisper-small' });
20 const [audioFile, setAudioFile] = useState<string | null>(null);
21 const [audioFileName, setAudioFileName] = useState<string>('');
22 const [result, setResult] = useState<CactusSTTTranscribeResult | null>(null);
23 const [embeddingResult, setEmbeddingResult] =
24 useState<CactusSTTAudioEmbedResult | null>(null);
25
26 useEffect(() => {
27 if (!cactusSTT.isDownloaded) {
28 cactusSTT.download();
29 }
30 // eslint-disable-next-line react-hooks/exhaustive-deps
31 }, [cactusSTT.isDownloaded]);
32
33 const handleInit = () => {
34 cactusSTT.init();
35 };
36
37 const handleSelectAudio = async () => {
38 try {
39 const res = await DocumentPicker.pick({
40 type: [DocumentPicker.types.audio],
41 });
42 if (res && res.length > 0) {
43 const fileName = `audio_${Date.now()}.wav`;
44 const destPath = `${RNFS.CachesDirectoryPath}/${fileName}`;
45 await RNFS.copyFile(res[0].uri, destPath);
46 setAudioFile(destPath);
47 setAudioFileName(res[0].name || 'Unknown');
48 }
49 } catch (err) {
50 console.error(err);
51 }
52 };
53
54 const handleTranscribe = async () => {
55 if (!audioFile) {
56 return;
57 }
58 const transcribeResult = await cactusSTT.transcribe({
59 audio: audioFile,
60 });
61 setResult(transcribeResult);
62 };
63
64 const handleAudioEmbed = async () => {
65 if (!audioFile) {
66 return;
67 }
68 const embedResult = await cactusSTT.audioEmbed({
69 audioPath: audioFile,
70 });
71 setEmbeddingResult(embedResult);
72 };
73
74 const handleStop = () => {
75 cactusSTT.stop();

Callers

nothing calls this directly

Calls 3

useCactusSTTFunction · 0.85
downloadMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected