diff --git a/example/infer.ps1 b/example/infer.ps1 new file mode 100644 index 0000000..1356474 --- /dev/null +++ b/example/infer.ps1 @@ -0,0 +1,45 @@ +# Copyright (c) 2025 SparkAudio +# 2025 Xinsheng Wang (w.xinshawn@gmail.com) +# 2025 Abao (ibaoger@hotmail.com) +# +# 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. + + +# Get the absolute path of the script's directory +$script_dir = Split-Path -Parent $MyInvocation.MyCommand.Path + +# Get the root directory +$root_dir = Split-Path -Parent $script_dir + +# Set default parameters +$device = 0 +$save_dir = 'example/results' +$model_dir = "pretrained_models/Spark-TTS-0.5B" +$text = "身临其境,换新体验。塑造开源语音合成新范式,让智能语音更自然。" +$prompt_text = "吃燕窝就选燕之屋,本节目由26年专注高品质燕窝的燕之屋冠名播出。豆奶牛奶换着喝,营养更均衡,本节目由豆本豆豆奶特约播出。" +$prompt_speech_path = "example/prompt_audio.wav" + +# Change directory to the root directory +Set-Location -Path $root_dir + +# Source the parse_options script +. "$root_dir\sparktts\utils\parse_options.ps1" + +# Run inference +python -m cli.inference ` + --text "$text" ` + --device "$device" ` + --save_dir "$save_dir" ` + --model_dir "$model_dir" ` + --prompt_text "$prompt_text" ` + --prompt_speech_path "$prompt_speech_path" \ No newline at end of file diff --git a/sparktts/utils/parse_options.ps1 b/sparktts/utils/parse_options.ps1 new file mode 100644 index 0000000..51f18de --- /dev/null +++ b/sparktts/utils/parse_options.ps1 @@ -0,0 +1,71 @@ +# Copyright (c) 2025 Abao (ibaoger@hotmail.com) + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the “Software”), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +# Parse command-line options. +# To be sourced by another script (as in ". parse_options.ps1"). +# Option format is: --option-name arg +# and PowerShell variable "$option_name" gets set to value "arg." +# The exception is --help, which takes no arguments, but prints the +# $help_message variable (if defined). + + +# Process command line arguments +while ($args.Length -gt 0) { + $arg = $args[0] + + # Handle --help option + if ($arg -eq "--help" -or $arg -eq "-h") { + if ([string]::IsNullOrEmpty($help_message)) { + Write-Host "No help found." -ForegroundColor Red + } else { + Write-Host $help_message + } + exit 0 + } + + # Handle other options + if ($arg -match "^--") { + if ($arg -match "=") { + Write-Host "Options to scripts must be of the form --name value, got '$arg'" -ForegroundColor Red + exit 1 + } + + # Extract variable name from argument + $name = $arg -replace "^--", "" -replace "-", "_" + + # Check if we have another argument as value + if ($args.Length -lt 2) { + Write-Host "Missing value for option $arg" -ForegroundColor Red + exit 1 + } + + # Get the value and update arguments array + $value = $args[1] + $args = $args[2..($args.Length-1)] + + # Set the variable in the parent scope + Set-Variable -Name $name -Value $value -Scope 1 + + } else { + # Not an option, move to next argument + $args = $args[1..($args.Length-1)] + } +} \ No newline at end of file