> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 列出相似音色

POST https://api.elevenlabs.io/v1/similar-voices
Content-Type: multipart/form-data

返回与提供音频样本相似的共享音色列表。如果未提供 similarity_threshold 和 top_k，将使用默认值。

Reference: https://elevenlabs.io/docs/api-reference/voices/find-similar-voices

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Body (multipart/form-data)

This endpoint expects a multipart form containing an optional file.

- `audio_file` (file, optional)
- `similarity_threshold` (double, optional) — 所提供样本与声音库音色之间的相似度阈值。取值范围为 0 至 2。值越小，返回的音色越相似。
- `top_k` (integer, optional) — 要返回的最相似音色数量。若提供 similarity_threshold，返回的音色可能少于此数量。取值范围为 1 到 100。

## Response

### 200

成功响应

- `voices` (list of LibraryVoiceResponseModel, required) — 共享音色列表
- `has_more` (boolean, required) — 后续页面中是否还有更多共享音色。
- `total_count` (integer, optional, default: 0) — 符合查询条件的共享音色总数。
- `last_sort_id` (string, optional, nullable)

## Errors

### 422 Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### LibraryVoiceResponseModel

- `public_owner_id` (string, required) — 音色公开所有者 ID。
- `voice_id` (string, required) — 音色的 ID。
- `date_unix` (integer, required) — 音色添加到声音库的日期，以 Unix 时间表示。
- `name` (string, required) — 音色名称。
- `accent` (string, required) — 音色的口音。
- `gender` (string, required) — 音色性别。
- `age` (string, required) — 音色的年龄。
- `descriptive` (string, required) — 音色描述。
- `use_case` (string, required) — 音色的使用场景。
- `category` (enum, required) — 音色类别。
  - Allowed values: `generated`, `cloned`, `premade`, `professional`, `famous`, `high_quality`
- `usage_character_count_1y` (integer, required) — 该音色过去 1 年的使用字符数。
- `usage_character_count_7d` (integer, required) — 该音色过去 7 天的使用字符数。
- `play_api_usage_character_count_1y` (integer, required) — 该音色过去一年通过播放 API 使用的字符数。
- `cloned_by_count` (integer, required) — 该音色被克隆的次数。
- `free_users_allowed` (boolean, required) — 是否允许免费用户使用该音色。
- `live_moderation_enabled` (boolean, required) — 是否为该音色启用实时审核。
- `featured` (boolean, required) — 音色是否为精选音色。
- `language` (string, optional, nullable) — 音色的语言。
- `locale` (string, optional, nullable) — 音色的区域设置。
- `description` (string, optional, nullable) — 音色描述。
- `preview_url` (string, optional, nullable) — 音色的预览 URL。
- `rate` (double, optional, nullable) — 音色的费率乘数。
- `fiat_rate` (double, optional, nullable) — 音色费率，以每 1000 积分的美元金额表示。默认值时为 null
- `verified_languages` (list of VerifiedVoiceLanguageResponseModel, optional, nullable) — 该音色已验证的语言。
- `notice_period` (integer, optional, nullable) — 音色的通知期。
- `instagram_username` (string, optional, nullable) — 音色的 Instagram 用户名。
- `twitter_username` (string, optional, nullable) — 该音色的 Twitter 用户名。
- `youtube_username` (string, optional, nullable) — 该音色的 YouTube 用户名。
- `tiktok_username` (string, optional, nullable) — 该音色的 TikTok 用户名。
- `image_url` (string, optional, nullable) — 音色图像的 URL。
- `is_added_by_user` (boolean, optional, nullable) — 音色是否由用户添加。
- `is_bookmarked` (boolean, optional, nullable) — 当前用户是否已收藏该音色。仅当 is_added_by_user 为 True 时相关。

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)

### VerifiedVoiceLanguageResponseModel

- `language` (string, required) — 音色的语言。
- `model_id` (string, required) — 音色的模型 ID。
- `accent` (string, optional, nullable) — 音色的口音（如适用）。
- `locale` (string, optional, nullable) — 音色的区域设置（如适用）。
- `preview_url` (string, optional, nullable) — 音色的预览 URL（如适用）。

### ValidationErrorLocItems

- string
- integer

## Examples

**Request**

```json
{
  "audio_file": "<file: <file1>>"
}
```

**Response**

```json
{
  "voices": [
    {
      "public_owner_id": "63e84100a6bf7874ba37a1bab9a31828a379ec94b891b401653b655c5110880f",
      "voice_id": "sB1b5zUrxQVAFl2PhZFp",
      "date_unix": 1714423232,
      "name": "Alita",
      "accent": "american",
      "gender": "Female",
      "age": "young",
      "descriptive": "calm",
      "use_case": "characters_animation",
      "category": "professional",
      "usage_character_count_1y": 12852,
      "usage_character_count_7d": 12852,
      "play_api_usage_character_count_1y": 12852,
      "cloned_by_count": 11,
      "free_users_allowed": true,
      "live_moderation_enabled": false,
      "featured": false,
      "language": "en",
      "description": "Perfectly calm, neutral and strong voice. Great for a young female protagonist.",
      "preview_url": "https://storage.googleapis.com/eleven-public-prod/wqkMCd9huxXHX1dy5mLJn4QEQHj1/voices/sB1b5zUrxQVAFl2PhZFp/55e71aac-5cb7-4b3d-8241-429388160509.mp3",
      "rate": 1,
      "verified_languages": [
        {
          "language": "en",
          "model_id": "eleven_multilingual_v2",
          "accent": "american",
          "locale": "en-US",
          "preview_url": "https://storage.googleapis.com/eleven-public-prod/wqkMCd9huxXHX1dy5mLJn4QEQHj1/voices/sB1b5zUrxQVAFl2PhZFp/55e71aac-5cb7-4b3d-8241-429388160509.mp3"
        }
      ]
    }
  ],
  "has_more": false,
  "total_count": 0
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/similar-voices"

files = { "audio_file": "open('<file1>', 'rb')" }
payload = {
    "similarity_threshold": ,
    "top_k": 
}

response = requests.post(url, data=payload, files=files)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/similar-voices';
const form = new FormData();
form.append('audio_file', '<file1>');
form.append('similarity_threshold', '');
form.append('top_k', '');

const options = {method: 'POST'};

options.body = form;

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.elevenlabs.io/v1/similar-voices"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"; filename=\"<file1>\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"similarity_threshold\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"top_k\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/similar-voices")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"; filename=\"<file1>\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"similarity_threshold\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"top_k\"\r\n\r\n\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.elevenlabs.io/v1/similar-voices")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"; filename=\"<file1>\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"similarity_threshold\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"top_k\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/similar-voices', [
  'multipart' => [
    [
        'name' => 'audio_file',
        'filename' => '<file1>',
        'contents' => null
    ]
  ]
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/similar-voices");
var request = new RestRequest(Method.POST);
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"; filename=\"<file1>\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"similarity_threshold\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"top_k\"\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation
let parameters = [
  [
    "name": "audio_file",
    "fileName": "<file1>"
  ],
  [
    "name": "similarity_threshold",
    "value": 
  ],
  [
    "name": "top_k",
    "value": 
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/similar-voices")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```