Last active
February 6, 2016 15:05
-
-
Save aetos382/434657cf4530815a8434 to your computer and use it in GitHub Desktop.
https://gist.github.com/aetos382/e737286380e99cfaf9e8 を無駄に関数化してみたっす
This file contains 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
function Play-SpeechText { | |
[CmdletBinding( | |
DefaultParameterSetName = 'Default', | |
ConfirmImpact = [System.Management.Automation.ConfirmIMpact]::Medium)] | |
param( | |
[Parameter(Mandatory)] | |
[string] $ApiKey, | |
[Parameter(Mandatory, Position = 0)] | |
[string] $Text, | |
[ValidateSet('show', 'haruka', 'hikari', 'takeru', 'santa', 'bear')] | |
[string] $Speaker = 'show', | |
[ValidateSet('happiness', 'sadness', 'anger')] | |
[string] $Emotion, | |
[ValidateRange(1, 4)] | |
[int] $EmotionLevel = 2, | |
[ValidateRange(50, 200)] | |
[int] $Pitch = 100, | |
[ValidateRange(50, 400)] | |
[int] $Speed = 100, | |
[ValidateRange(50, 200)] | |
[int] $Volume = 100, | |
[Parameter(ParameterSetName = 'OutToFile', Mandatory)] | |
[string] $OutFile, | |
[Parameter(ParameterSetName = 'OutToFile')] | |
[ValidateSet('wav', 'ogg', 'aac')] | |
[string] $Format = 'wav') | |
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("${ApiKey}:")) | |
$headers = @{ | |
Authorization = "Basic $token" | |
} | |
$body = @{ | |
text = $Text | |
speaker = $Speaker | |
pitch = $Pitch | |
speed = $Speed | |
volume = $Volume | |
} | |
if ($PSBoundParameters.ContainsKey('Emotion')) { | |
$body.emotion = $Emotion | |
$body.emotion_level = $EmotionLevel | |
} | |
$params = @{} | |
$outToFile = $PSCmdlet.ParameterSetName -eq 'OutToFile' | |
if ($outToFile) | |
{ | |
$params.OutFile = $OutFile | |
$body.format = $Format | |
} | |
$response = Invoke-WebRequest -Uri 'https://api.voicetext.jp/v1/tts' -Method Post -Body $body -Headers $headers @params | |
if (!$outToFile) { | |
$player = New-Object 'System.Media.SoundPlayer' $response.RawContentStream | |
$player.PlaySync() | |
$player.Dispose() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment