Error 503

#68
by VishnuBhanderi - opened

I am facing an issue while trying to get transcribed text in my React native application. I am using this model through Interface API.

Here is my code.

    const startRecording = async () => {
      try {
        if (isRecordingStopped) {
          const { status } = await Audio.requestPermissionsAsync();
    
          if (status !== "granted") {
            console.error("Audio recording permission not granted.");
            return;
          }
    
          const recordingObject = new Audio.Recording();
          await recordingObject.prepareToRecordAsync(
            Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY
          );
    
          setRecording(recordingObject);
          setIsRecording(true);
          setIsRecordingStopped(false);
    
          // Start the recording
          await recordingObject.startAsync();
        }
      } catch (error) {
        console.error("Error starting recording:", error);
      }
    };

Now, we are stoping recording and saving recorded audio in audioData file.

    const stopRecording = async () => {
      try {
        if (isRecording) {
          // Stop the recording
          await recording.stopAndUnloadAsync();
          setIsRecording(false);
          setIsRecordingStopped(true); // Set it to true when recording is stopped
    
          const audioData = recording.getURI();
  
          // Save the audio data to localStorage
          localStorage.setItem("audioData", audioData);
    
          // After stopping the recording, transcribe the audio
          await transcribeAudio(audioData);
        }
      } catch (error) {
        console.error("Error stopping recording:", error);
      }
    };

Now we are using audioData as file in transcribeAudio function.

    const transcribeAudio = async (audioData) => {
      try {
        const response = await fetch("https://api-inference.huggingface.co/models/openai/whisper-large-v2", {
          method: "POST",
          headers: {
            Authorization: "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXX",
          },
          body: audioData,
        });
    
        if (response.ok) {
          const result = await response.json();
          if (result && result.length > 0) {
            setTranscription(result[0].text);
          } else {
            setTranscription("Transcription not available.");
          }
        } else {
          // Handle non-200 HTTP response status
          console.error("Error transcribing audio. HTTP Status:", response.status);
        }
      } catch (error) {
        console.error("Error transcribing audio:", error);
      }
    };

Please suggest the solution

My Error Message :

E:\New folder\PersonalInterview\app\index.js:120     POST https://api-inference.huggingface.co/models/openai/whisper-large-v2 503
E:\New folder\PersonalInterview\node_modules\@expo\metro-runtime\build\error-overlay\LogBox.web.js:99 Error transcribing audio. HTTP Status: 503

Sign up or log in to comment