For the complete documentation index, see llms.txt. This page is also available as Markdown.

Setup Voice Verification

Uploading Api details to matches enrolled user's audio files with target user's audio file

try {
    const formData = new FormData();

    // Append first enroll recording in wav format
    const enroll1Path = `${RNFS.DocumentDirectoryPath}/${username}_0.wav`;
    const exists1 = await RNFS.exists(enroll1Path);
    if (!exists1) {
      throw new Error(`Enroll recording 0 not found at ${enroll1Path}`);
    }

    formData.append('sourceone', {
      uri: Platform.OS === 'android' ? `file://${enroll1Path}` : enroll1Path,
      type: 'audio/wav',
      name: 'sourceone.wav',
    });

    // Append second enroll recording in wav format
    const enroll2Path = `${RNFS.DocumentDirectoryPath}/${username}_1.wav`;
    const exists2 = await RNFS.exists(enroll2Path);
    if (!exists2) {
      throw new Error(`Enroll recording 1 not found at ${enroll2Path}`);
    }
    formData.append('sourcetwo', {
      uri: Platform.OS === 'android' ? `file://${enroll2Path}` : enroll2Path,
      type: 'audio/wav',
      name: 'sourcetwo.wav',
    });

    // Append third enroll recording in wav format
    const enroll3Path = `${RNFS.DocumentDirectoryPath}/${username}_2.wav`;
    const exists3 = await RNFS.exists(enroll3Path);
    if (!exists3) {
      throw new Error(`Enroll recording 2 not found at ${enroll3Path}`);
    }
    formData.append('sourcethree', {
      uri: Platform.OS === 'android' ? `file://${enroll3Path}` : enroll3Path,
      type: 'audio/wav',
      name: 'sourcethree.wav',
    });

    // Append verify recording in wav format
    if (!verifyFilePath) {
      throw new Error('Verification file path not provided');
    }
    const verifyExists = await RNFS.exists(verifyFilePath);
    if (!verifyExists) {
      throw new Error(`Verification file not found at ${verifyFilePath}`);
    }
    formData.append('target', {
      uri: Platform.OS === 'android' ? `file://${verifyFilePath}` : verifyFilePath,
      type: 'audio/wav',
      name: 'target.wav',
    });

    // Send the FormData payload.
    const response = await fetch('Your API', {
      method: 'POST',
      body: formData,
      // Let fetch set the Content-Type header automatically.
    });
    if (response.status === 200) {
      const responseBody = await response.text();
      console.log(responseBody);
      const parsedResponse = JSON.parse(responseBody);
      const score = parsedResponse.score;
      Alert.alert('Matching Score', score);
    } else {
      throw new Error(`Upload failed with status ${response.status}`);
    }
  } catch (error) {
    Alert.alert('Error during upload', error.message);
  }

Last updated