I Use CoPilot To Program Python Elevenlabs.io API fetch TTS audio file

Sdílet
Vložit
  • čas přidán 5. 09. 2024
  • Should you not want to watch my 1 hour 47 minute version. Well, it worked perfectly. I didn't have to put on my python hat. I was able to create a time-saving utility in 10 minutes.

Komentáře • 4

  • @bibhu96
    @bibhu96 Před 5 měsíci

    Thanks a lot sir🤝

  • @bibhu96
    @bibhu96 Před 5 měsíci

    Hi sir,
    I use your code same, but the excat voice I didn’t get when I do it in browser by selecting that similar option as same in similar to code. Could I connect with you regarding this issue?

    • @MaxoticsTV
      @MaxoticsTV  Před 5 měsíci

      sure you can reach me at maxrottersman gmail you probably want to get your voices with this kind of code:
      # Open the file and read the API key
      with open(api_key_file, 'r') as file:
      myAPI = file.read().strip()
      # An API key is defined here. You'd normally get this from the service you're accessing. It's a form of authentication.
      XI_API_KEY = myAPI
      # This is the URL for the API endpoint we'll be making a GET request to.
      url = "api.elevenlabs.io/v1/voices"
      # Here, headers for the HTTP request are being set up.
      # Headers provide metadata about the request. In this case, we're specifying the content type and including our API key for authentication.
      headers = {
      "Accept": "application/json",
      "xi-api-key": XI_API_KEY,
      "Content-Type": "application/json"
      }
      # A GET request is sent to the API endpoint. The URL and the headers are passed into the request.
      response = requests.get(url, headers=headers)
      # The JSON response from the API is parsed using the built-in .json() method from the 'requests' library.
      # This transforms the JSON data into a Python dictionary for further processing.
      data = response.json()
      # A loop is created to iterate over each 'voice' in the 'voices' list from the parsed data.
      # The 'voices' list consists of dictionaries, each representing a unique voice provided by the API.
      for voice in data['voices']:
      # For each 'voice', the 'name' and 'voice_id' are printed out.
      # These keys in the voice dictionary contain values that provide information about the specific voice.
      print(f"{voice['name']}; {voice['voice_id']}")
      # Open the output file in write mode
      with open('voices.txt', 'w') as file:
      # Check if the request was successful
      if response.status_code == 200:
      # Parse the JSON response
      voices_data = response.json()
      # Process the data as needed, for example, writing the list of voices to the file
      for voice in voices_data['voices']:
      file.write(f"{voice['name']}|{voice['voice_id']}
      ")
      else:
      file.write(f"Error: {response.status_code} {response.text}
      ")

    • @bibhu96
      @bibhu96 Před 5 měsíci

      Hi sir,
      I followed same process as you suggested but, voice quality is different from voice generated by chrome browser is best as compared to python code.
      All mp3 and code I shared on your mail. I am working for Hindi voice language.
      Could please check once sir.
      I