English 中文(简体)
反应式代用品管理了未经开张支持的电器记录
原标题:react-native expo managed app recording not supported by openai

I m 从露天 transcript末点接回这一错误;

message: "The audio file could not be decoded or its format is not supported." 

我做的是:

  • Setting recording options to mp4;
  • Move the new recording into a temporary file Directory;
  • Create form data and call openai transcriptions endpoint;

发生的情况:

这就是我做的事情。

  async function startRecording() {
    try {
      // needed for IoS
      if (audioPermission) {
        await Audio.setAudioModeAsync({
          allowsRecordingIOS: true,
          playsInSilentModeIOS: true,
        });
      }

      const newRecording = new Audio.Recording();

      const recordingOptions = {
        android: {
          extension:  .mp4 ,
          outputFormat: Audio.RECORDING_OPTION_ANDROID_OUTPUT_FORMAT_MPEG_4,
          audioEncoder: Audio.RECORDING_OPTION_ANDROID_AUDIO_ENCODER_AAC,
        },
        ios: {
          extension:  .mp4 ,
          outputFormat: Audio.RECORDING_OPTION_IOS_OUTPUT_FORMAT_MPEG4AAC,
          audioQuality: Audio.RECORDING_OPTION_IOS_AUDIO_QUALITY_HIGH,
        },
      };

      console.log( Starting Recording )
      await newRecording.prepareToRecordAsync(
        recordingOptions
      );

      await newRecording.startAsync();
      setRecording(newRecording);
      setRecordingStatus( recording );

    } catch (error) {
      console.error( Failed to start recording , error);
    }
  }

  async function stopRecording() {
    try {
      if (recordingStatus ==  recording ) {
        console.log( Stopping recording.. );
        await recording.stopAndUnloadAsync();
        const recordingUri = recording.getURI();
        console.log( Recording stopped and stored at URI , recordingUri);
        console.log( OPENAI_API_KEY , OPENAI_API_KEY);
        // Create a file name for the new recording
        const fileName = `recording-${Date.now()}.mp4`;

        // Calls openai translations endpoint
        try {
          const url =  https://api.openai.com/v1/audio/transcriptions ;
          const headers = {
             Authorization : `Bearer ${OPENAI_API_KEY}`,
             Content-Type :  multipart/form-data ,
          };

          // Copy the recording file to a temporary directory
          const tempDirectory = FileSystem.cacheDirectory +  recordings/ ;
          await FileSystem.makeDirectoryAsync(tempDirectory, { intermediates: true });
          const tempRecordingUri = tempDirectory + fileName;
          await FileSystem.copyAsync({
            from: recordingUri,
            to: tempRecordingUri,
          });


          const formData = new FormData();
          formData.append( file , {
            uri: tempRecordingUri,
            name: fileName,
            type:  audio/mp4 , // Change to the desired audio format
          });
          formData.append( model ,  whisper-1 );

          // const formData = new FormData();
          // formData.append( file , fileData, fileName);
          // formData.append( model ,  whisper-1 );

          axios.post(url, formData, { headers })
            .then(response => {
              console.log( Transcription response: , response.data);
            })
            .catch(error => {
              console.error( Error: , error);
            });

        } catch (error) {
          console.error(error);
        }
      }
    }
    catch (error) {
      console.error( Failed to stop recording , error);
    }
  }
问题回答

暂无回答




相关问题
How do I connect Alexa to ChatGPT

I m trying to connect Alexa to openAI s API using my APIkey for chat completions and not sure where to write the code for the function in the Alexa Skills Kit. In the Lambda file there are: index.js, ...

CHATGPT Integration [closed]

Can anyone please let me know the steps to integrate ChatGPT in to a website using Api with python I am expecting Chat GPT integration process in to a website for my process. So please let me know the ...

Open AI finish response LENGTH

I am calling open AI api with below details and I am getting below response { value : { outputs : [{ finishReason : LENGTH , text : The summary in this JSON format is as follows: short_ , ...

热门标签