[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-05-08 UTC."],[],[],null,["# tflite_support.task.audio.AudioEmbedder\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/audio_embedder.py#L47-L167) |\n\nClass that performs dense feature vector extraction on audio. \n\n tflite_support.task.audio.AudioEmbedder(\n options: ../../../tflite_support/task/audio/AudioEmbedderOptions,\n cpp_embedder: _CppAudioEmbedder\n ) -\u003e None\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|------------------------------|----------------------------------------------------|\n| `number_of_output_layers` | Gets the number of output layers of the model. |\n| `required_audio_format` | Gets the required audio format for the model. |\n| `required_input_buffer_size` | Gets the required input buffer size for the model. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `cosine_similarity`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/audio_embedder.py#L133-L136) \n\n cosine_similarity(\n u: ../../../tflite_support/task/processor/FeatureVector,\n v: ../../../tflite_support/task/processor/FeatureVector\n ) -\u003e float\n\nComputes cosine similarity \\[1\\] between two feature vectors.\n\n### `create_audio_record`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/audio_embedder.py#L105-L113) \n\n create_audio_record() -\u003e ../../../tflite_support/task/audio/AudioRecord\n\nCreates an AudioRecord instance to record audio.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| An AudioRecord instance. ||\n\n\u003cbr /\u003e\n\n### `create_from_file`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/audio_embedder.py#L56-L73) \n\n @classmethod\n create_from_file(\n file_path: str\n ) -\u003e 'AudioEmbedder'\n\nCreates the `AudioEmbedder` object from a TensorFlow Lite model.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------|--------------------|\n| `file_path` | Path to the model. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `AudioEmbedder` object that's created from `options`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|-----------------------------------------------------------------------------------------|\n| `ValueError` | If failed to create `AudioEmbedder` object from the provided file such as invalid file. |\n| `RuntimeError` | If other types of error occurred. |\n\n\u003cbr /\u003e\n\n### `create_from_options`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/audio_embedder.py#L75-L93) \n\n @classmethod\n create_from_options(\n options: ../../../tflite_support/task/audio/AudioEmbedderOptions\n ) -\u003e 'AudioEmbedder'\n\nCreates the `AudioEmbedder` object from audio embedder options.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------|--------------------------------------|\n| `options` | Options for the audio embedder task. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `AudioEmbedder` object that's created from `options`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|---------------------------------------------------------------------------------------------------|\n| `ValueError` | If failed to create `AudioEmbedder` object from `AudioEmbedderOptions` such as missing the model. |\n| `RuntimeError` | If other types of error occurred. |\n\n\u003cbr /\u003e\n\n### `create_input_tensor_audio`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/audio_embedder.py#L95-L103) \n\n create_input_tensor_audio() -\u003e ../../../tflite_support/task/audio/TensorAudio\n\nCreates a TensorAudio instance to store the audio input.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A TensorAudio instance. ||\n\n\u003cbr /\u003e\n\n### `embed`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/audio_embedder.py#L115-L131) \n\n embed(\n audio: ../../../tflite_support/task/audio/TensorAudio\n ) -\u003e ../../../tflite_support/task/processor/EmbeddingResult\n\nPerforms actual feature vector extraction on the provided audio.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|----------------------------------------------------|\n| `audio` | Tensor audio, used to extract the feature vectors. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| embedding result. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|----------------------------------------------|\n| `ValueError` | If any of the input arguments is invalid. |\n| `RuntimeError` | If failed to calculate the embedding vector. |\n\n\u003cbr /\u003e\n\n### `get_embedding_dimension`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/audio_embedder.py#L138-L148) \n\n get_embedding_dimension(\n output_index: int\n ) -\u003e int\n\nGets the dimensionality of the embedding output.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------|-----------------------------------|\n| `output_index` | The output index of output layer. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| Dimensionality of the embedding output by the output_index'th output layer. Returns -1 if `output_index` is out of bounds. ||\n\n\u003cbr /\u003e"]]