#Chat GPT Not Responding to Voice Input

1 messages · Page 1 of 1 (latest)

timber heart
#

Code:

import React, { useState, useEffect } from 'react';
import SpeechRecognition, { useSpeechRecognition } from 'react-speech-recognition';
import '../index.css';

const SpeechToText = () => {
  const [continuousMode, setContinuousMode] = useState(false);
  const [chatGptResponse, setChatGptResponse] = useState('');
  const {
    transcript,
    listening,
    resetTranscript,
    browserSupportsSpeechRecognition
  } = useSpeechRecognition();

  const API_KEY = 'sk-9wso6M------mytoken';

  const startListening = () => {
    const options = continuousMode && !listening ? { continuous: true } : {};
    SpeechRecognition.startListening(options);
  };

  const toggleContinuousMode = () => {
    if (!listening) {
      setContinuousMode(!continuousMode);
    }
  };

  const callChatGPT = async (voiceInput) => {
    const response = await fetch('https://api.openai.com/v1/engines/davinci-codex/completions', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${API_KEY}`
      },
      body: JSON.stringify({
        prompt: voiceInput,
        max_tokens: 600
      })
    });
  
    const data = await response.json();
    if (Array.isArray(data.choices) && data.choices.length > 0) {
      return data.choices[0].text;
    } else {
      console.error('No choices in the response', data);
      return '';
    }
  };
  
  
  
  useEffect(() => {
    if (!listening && transcript) {
      callChatGPT(transcript).then(response => setChatGptResponse(response));
    }
  }, [listening, transcript]);

  if (!browserSupportsSpeechRecognition) {
    return <span>Browser doesn't support speech recognition.</span>;
  }

  return (
    <div className="speech-container">
      <p>Microphone: {listening ? 'on' : 'off'}</p>
      <button className="speech-button" onClick={startListening}>Start</button>
      <button className="speech-button speech-button-stop" onClick={SpeechRecognition.stopListening}>Stop</button>
      <button className="speech-button speech-button-reset" onClick={resetTranscript}>Reset</button>
      <div>
        <span>Continuous Mode:</span>
        <label className={`speech-toggle ${listening ? 'disabled' : ''}`}>
          <input
            type="checkbox"
            checked={continuousMode}
            onChange={toggleContinuousMode}
            disabled={listening}
          />
          <span className="speech-slider"></span>
        </label>
      </div>
      <p className="transcript">{transcript}</p>
      <p className="response">{chatGptResponse}</p>
    </div>
  );
};

export default SpeechToText;
#

help would be appreciated

waxen viper
timber heart
#

Yes

#

I have the transcription right under the continuous mode toggle

timber heart
timber heart
#

bump

vocal pewter
# timber heart bump

your code is using years old api address and a model that was removed over half a year ago