Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions apps/speech/screens/SpeechToTextScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,28 @@ export const SpeechToTextScreen = ({ onBack }: { onBack: () => void }) => {
AudioManager.requestRecordingPermissions();
}, []);

async function getAudioFile(sourceUri: string) {
const destination = FileSystem.cacheDirectory + 'audio_file.wav';

if (sourceUri.startsWith('http')) {
const { uri } = await FileSystem.downloadAsync(sourceUri, destination);
return uri;
} else {
await FileSystem.copyAsync({
from: sourceUri,
to: destination,
});
return destination;
}
}

const handleTranscribeFromURL = async () => {
if (!audioURL.trim()) {
console.warn('Please provide a valid audio file URL');
return;
}

const { uri } = await FileSystem.downloadAsync(
audioURL,
FileSystem.cacheDirectory + 'audio_file'
);
const uri = await getAudioFile(audioURL);

const audioContext = new AudioContext({ sampleRate: 16000 });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class ASR {
// The maximum number of tokens the decoder can generate per chunk
constexpr static int32_t kMaxDecodeLength = 128;
// Maximum duration of each audio chunk to process (in seconds)
constexpr static int32_t kChunkSize = 30;
// It is intentionally set to 29 since otherwise only the last chunk would be
// correctly transcribe due to the model's positional encoding limit
constexpr static int32_t kChunkSize = 29;
// Sampling rate expected by Whisper and the model's audio pipeline (16 kHz)
constexpr static int32_t kSamplingRate = 16000;
// Minimum allowed chunk length before processing (in audio samples)
Expand Down
Loading