-
Notifications
You must be signed in to change notification settings - Fork 237
Add speaker embeddings support #3855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1d5fb31
Add speaker ambeddings support
michalkulakowski 771aec8
fix
michalkulakowski 2999a32
fix
michalkulakowski af90182
style
michalkulakowski 45302f3
fix
michalkulakowski 2971118
fix
michalkulakowski 9288149
fix
michalkulakowski a4350d6
missing file
michalkulakowski 20040a2
fix
michalkulakowski 6be6b58
uts refactor
michalkulakowski e9350a6
UTs
michalkulakowski aa8b340
style
michalkulakowski 91e4a97
fix
michalkulakowski 3dde288
style
michalkulakowski ad2cbaa
style
michalkulakowski 9bd32a4
fix
michalkulakowski 72f4b5b
style
michalkulakowski a09563f
Update src/test/audio/text2speech_test.cpp
michalkulakowski fda1859
Update demos/audio/README.md
michalkulakowski fe9a02d
Update src/audio/text_to_speech/t2s_calculator.cc
michalkulakowski ddf3de4
Update src/audio/text_to_speech/t2s_servable.cpp
michalkulakowski 3bd9d80
review fix
michalkulakowski 2452659
fix
michalkulakowski 8161016
fix
michalkulakowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ LEGACY_MODEL_FILE="1/model.bin" | |
| EMBEDDING_MODEL="thenlper/gte-small" | ||
| RERANK_MODEL="BAAI/bge-reranker-base" | ||
| VLM_MODEL="OpenGVLab/InternVL2-1B" | ||
| TTS_MODEL="microsoft/speecht5_tts" | ||
|
|
||
| # Models for tools testing. Only tokenizers are downloaded. | ||
| QWEN3_MODEL="Qwen/Qwen3-8B" | ||
|
|
@@ -78,6 +79,16 @@ if [ ! -f "$1/$FACEBOOK/chat_template.jinja" ]; then | |
| cp src/test/llm/dummy_facebook_template.jinja "$1/$FACEBOOK/chat_template.jinja" | ||
| fi | ||
|
|
||
| if [ -f "$1/$TTS_MODEL/$TOKENIZER_FILE" ]; then | ||
| echo "Model file $1/$TTS_MODEL/$TOKENIZER_FILE exists. Skipping downloading models." | ||
| else | ||
| python3 demos/common/export_models/export_model.py text2speech --source_model "$TTS_MODEL" --weight-format int4 --model_repository_path $1 --vocoder microsoft/speecht5_hifigan | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about windows script? |
||
| fi | ||
| if [ ! -f "$1/$TTS_MODEL/$TOKENIZER_FILE" ]; then | ||
| echo "[ERROR] Model file $1/$TTS_MODEL/$TOKENIZER_FILE does not exist." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -f "$1/$VLM_MODEL/$TOKENIZER_FILE" ]; then | ||
| echo "Model file $1/$VLM_MODEL/$TOKENIZER_FILE exists. Skipping downloading models." | ||
| else | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| //***************************************************************************** | ||
| // Copyright 2026 Intel Corporation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //***************************************************************************** | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
| #include <fstream> | ||
|
|
||
| #include "openvino/genai/whisper_pipeline.hpp" | ||
| #include "openvino/genai/speech_generation/text2speech_pipeline.hpp" | ||
| #include "src/audio/text_to_speech/t2s_calculator.pb.h" | ||
| #include "src/status.hpp" | ||
| #include "src/logging.hpp" | ||
| #include "src/json_parser.hpp" | ||
|
|
||
| #include "src/audio/text_to_speech/t2s_servable.hpp" | ||
|
|
||
| namespace ovms { | ||
|
|
||
| static ov::Tensor read_speaker_embedding(const std::filesystem::path& file_path) { | ||
| std::ifstream input(file_path, std::ios::binary); | ||
| if (input.fail()) { | ||
| std::stringstream ss; | ||
| ss << "Failed to open file: " << file_path.string(); | ||
| throw std::runtime_error(ss.str()); | ||
| } | ||
|
|
||
| // Get file size | ||
| input.seekg(0, std::ios::end); | ||
| size_t buffer_size = static_cast<size_t>(input.tellg()); | ||
| input.seekg(0, std::ios::beg); | ||
|
|
||
| // Check size is multiple of float | ||
| if (buffer_size % sizeof(float) != 0) { | ||
| throw std::runtime_error("File size is not a multiple of float size."); | ||
| } | ||
| size_t num_floats = buffer_size / sizeof(float); | ||
| if (num_floats != 512) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 512? |
||
| throw std::runtime_error("File must contain speaker embedding including 512 32-bit floats."); | ||
| } | ||
|
|
||
| ov::Tensor floats_tensor(ov::element::f32, ov::Shape{1, num_floats}); | ||
| input.read(reinterpret_cast<char*>(floats_tensor.data()), buffer_size); | ||
| if (input.fail()) { | ||
| throw std::runtime_error("Failed to read all data from file."); | ||
| } | ||
|
|
||
| return floats_tensor; | ||
| } | ||
|
|
||
| TtsServable::TtsServable(const std::string& modelDir, const std::string& targetDevice, const google::protobuf::RepeatedPtrField<mediapipe::T2sCalculatorOptions_SpeakerEmbeddings>& graphVoices, const std::string& pluginConfig, const std::string& graphPath) { | ||
| auto fsModelsPath = std::filesystem::path(modelDir); | ||
| if (fsModelsPath.is_relative()) { | ||
| parsedModelsPath = (std::filesystem::path(graphPath) / fsModelsPath); | ||
| } else { | ||
| parsedModelsPath = fsModelsPath; | ||
| } | ||
| ov::AnyMap config; | ||
| Status status = JsonParser::parsePluginConfig(pluginConfig, config); | ||
| if (!status.ok()) { | ||
| SPDLOG_ERROR("Error during llm node plugin_config option parsing to JSON: {}", pluginConfig); | ||
| throw std::runtime_error("Error during plugin_config option parsing"); | ||
| } | ||
| ttsPipeline = std::make_shared<ov::genai::Text2SpeechPipeline>(parsedModelsPath.string(), targetDevice, config); | ||
| for (auto voice : graphVoices) { | ||
| if (!std::filesystem::exists(voice.path())) | ||
| throw std::runtime_error{"Requested voice speaker embeddings file does not exist: " + voice.path()}; | ||
| voices[voice.name()] = read_speaker_embedding(voice.path()); | ||
| } | ||
| } | ||
| } // namespace ovms | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "model_config_list": [], | ||
| "mediapipe_config_list": [ | ||
| { | ||
| "name":"text2speech", | ||
| "base_path":"/ovms/src/test/audio/", | ||
| "graph_path":"/ovms/src/test/audio/graph.pbtxt" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright 2026 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| input_stream: "HTTP_REQUEST_PAYLOAD:input" | ||
| output_stream: "HTTP_RESPONSE_PAYLOAD:output" | ||
|
|
||
| node { | ||
| name: "ttsNode1" | ||
| input_side_packet: "TTS_NODE_RESOURCES:t2s_servable" | ||
| calculator: "T2sCalculator" | ||
| input_stream: "HTTP_REQUEST_PAYLOAD:input" | ||
| output_stream: "HTTP_RESPONSE_PAYLOAD:output" | ||
| node_options: { | ||
| [type.googleapis.com / mediapipe.T2sCalculatorOptions]: { | ||
| models_path: "/ovms/src/test/llm_testing/microsoft/speecht5_tts" | ||
| plugin_config: '{"NUM_STREAMS": "1" }', | ||
| target_device: "CPU" | ||
| voices: [ | ||
| { | ||
| name: "speaker1", | ||
| path: "/ovms/src/test/audio/speaker.bin", | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } |
Empty file.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yet another link for manual change, it wouldnt even hit sed command which i use because its genai and master
do we want to keep this reference to master and risk of change and getting outdated demos? or do we want to hardcode it? or maybe do we want to keep it in our repo?