jhudsl / mscstts

R Client for the Microsoft Cognitive Services Text to Speech REST API
GNU General Public License v3.0
8 stars 6 forks source link

Error in ms_synthesize(script = "hey, how are you doing? I'm doing pretty good", : Forbidden (HTTP 403). #13

Open doh-FXX0303 opened 2 years ago

doh-FXX0303 commented 2 years ago

I'm getting a forbidden HTTP 403 error. I've been able to use the text to speech via Python using the same API key, so I don't think the issue lies with my Azure account. Below is the code I ran based on your example:

library(mscstts)
if (ms_have_tts_key()) {
  res = ms_synthesize(
    script = "hey, how are you doing? I'm doing pretty good",
    output_format = "audio-16khz-128kbitrate-mono-mp3")
  tmp <- tempfile("example", fileext = ".mp3")
  writeBin(res$content, con = tmp)
  mp3 = tuneR::readMP3(tmp)
}
testthat::expect_true(file.size(tmp) > 50000)
if (interactive()) {
  player = tuneR::getWavPlayer()
  if (.Platform$OS.type == "windows" && is.null(player)) player = NULL
  if (.Platform$OS.type != "windows" && is.null(player)) player = "play"
  tuneR::play(mp3, player = player)
}
muschellij2 commented 1 year ago

Thank you for the email. Unfortunately, I cannot actively maintain this package. Can you at least print out the 403 error message to see if there was more information?

Best, John

On Fri, Sep 9, 2022 at 2:44 PM Fan Xiong @.***> wrote:

I'm getting a forbidden HTTP 403 error. I've been able to use the text to speech via Python using the same API key, so I don't think the issue lies with my Azure account. Below is the code I ran based on your example:

library(mscstts) if (ms_have_tts_key()) { res = ms_synthesize( script = "hey, how are you doing? I'm doing pretty good", output_format = "audio-16khz-128kbitrate-mono-mp3") tmp <- tempfile("example", fileext = ".mp3") writeBin(res$content, con = tmp) mp3 = tuneR::readMP3(tmp) } testthat::expect_true(file.size(tmp) > 50000) if (interactive()) { player = tuneR::getWavPlayer() if (.Platform$OS.type == "windows" && is.null(player)) player = NULL if (.Platform$OS.type != "windows" && is.null(player)) player = "play" tuneR::play(mp3, player = player) }

— Reply to this email directly, view it on GitHub https://github.com/muschellij2/mscstts/issues/13, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGPLQUAAXN5Y7NVOQXPLDV5OARDANCNFSM6AAAAAAQI5LGQM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

doh-FXX0303 commented 1 year ago

Microsoft pointed me to this site (Troubleshoot the Speech SDK - Speech service - Azure Cognitive Services | Microsoft Learnhttps://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/troubleshooting) and said the error might be in the R package, since my API key and authorization token were all valid and working in the python package (azure.cognitiveservices.speech). So, something in the R package might not be passing the API key correctly to Azure. There wasn't anything else printed other than the HTTP 403 error indicating either an invalid API or a quota being reached. My free Azure subscription has expired now, so this may have to wait until I have it re-enabled again.

Thanks,

Fan Xiong, MPH Epidemiologist 3 (Non-Medical) Prescription Monitoring Program (PMP) Health Systems and Quality Assurance Washington State Department of Health Gender Pronouns: He/Him/His @.**@.> 360-789-9387 | www.doh.wa.govhttp://www.doh.wa.gov/ @.***https://www.doh.wa.gov/Newsroom/SocialMedia

@.*** Sign up for the POP Initiativehttps://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdoh.wa.gov%2Fpop&data=04%7C01%7CJillian.Jetson%40doh.wa.gov%7C76e572249482436b0f7608d976e3af8b%7C11d0e217264e400a8ba057dcc127d72d%7C0%7C0%7C637671542556686135%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=I51NDDHKSWXC27zfBVt2mZr0VxXnp38HWkejcQ1jn0Q%3D&reserved=0 [Title: DOH Twitter - Description: DOH Twitter account]https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftwitter.com%2Fwadepthealth%3Flang%3Den&data=04%7C01%7CJillian.Jetson%40doh.wa.gov%7Ca7ee615cb0654a7c244b08d90f271dbb%7C11d0e217264e400a8ba057dcc127d72d%7C0%7C0%7C637557482950588932%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Gx5Ernjmui6%2FIAekULePhk0pB413nGy5DMr0tXZ%2Bhi0%3D&reserved=0[Title: DOH Facebook - Description: DOH Facebook account]https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.facebook.com%2FWADeptHealth%2F&data=04%7C01%7CJillian.Jetson%40doh.wa.gov%7Ca7ee615cb0654a7c244b08d90f271dbb%7C11d0e217264e400a8ba057dcc127d72d%7C0%7C0%7C637557482950588932%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=3XFascXyHwkkAp2fVhqwR6tW2W4sCl5jIoW6EDCQKYs%3D&reserved=0[Title: DOH Instagram - Description: DOH Instagram account]https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.instagram.com%2Fwadepthealth%2F&data=04%7C01%7CJillian.Jetson%40doh.wa.gov%7Ca7ee615cb0654a7c244b08d90f271dbb%7C11d0e217264e400a8ba057dcc127d72d%7C0%7C0%7C637557482950598886%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=lxoUnMT3yTSgUeL0BhyyKtn%2ByZ%2B8OMjEH%2FfgX9CkE7I%3D&reserved=0[Title: DOH YouTube - Description: DOH YouTube account]https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUCTSCpezTD0TjiiAOuJY7f5w%2Fdoh&data=04%7C01%7CJillian.Jetson%40doh.wa.gov%7Ca7ee615cb0654a7c244b08d90f271dbb%7C11d0e217264e400a8ba057dcc127d72d%7C0%7C0%7C637557482950598886%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=OUdWvQ8Po0fjIH%2B9V%2BNJaBngXdOTmAkC0TekTPPJg0I%3D&reserved=0[Title: DOH Medium Blog - Description: DOH Medium Blog account]https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmedium.com%2F%40WADeptHealth&data=04%7C01%7CJillian.Jetson%40doh.wa.gov%7Ca7ee615cb0654a7c244b08d90f271dbb%7C11d0e217264e400a8ba057dcc127d72d%7C0%7C0%7C637557482950608842%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=AUQZqk4osbq8HMkRJ1AmOCfTdDpWuCGZ3tYenwtmcEc%3D&reserved=0

From: John Muschelli @.> Sent: Tuesday, October 11, 2022 2:19 AM To: muschellij2/mscstts @.> Cc: Xiong, Fan (DOH) @.>; Author @.> Subject: Re: [muschellij2/mscstts] Error in ms_synthesize(script = "hey, how are you doing? I'm doing pretty good", : Forbidden (HTTP 403). (Issue #13)

External Email Thank you for the email. Unfortunately, I cannot actively maintain this package. Can you at least print out the 403 error message to see if there was more information?

Best, John

On Fri, Sep 9, 2022 at 2:44 PM Fan Xiong @.<mailto:@.>> wrote:

I'm getting a forbidden HTTP 403 error. I've been able to use the text to speech via Python using the same API key, so I don't think the issue lies with my Azure account. Below is the code I ran based on your example:

library(mscstts) if (ms_have_tts_key()) { res = ms_synthesize( script = "hey, how are you doing? I'm doing pretty good", output_format = "audio-16khz-128kbitrate-mono-mp3") tmp <- tempfile("example", fileext = ".mp3") writeBin(res$content, con = tmp) mp3 = tuneR::readMP3(tmp) } testthat::expect_true(file.size(tmp) > 50000) if (interactive()) { player = tuneR::getWavPlayer() if (.Platform$OS.type == "windows" && is.null(player)) player = NULL if (.Platform$OS.type != "windows" && is.null(player)) player = "play" tuneR::play(mp3, player = player) }

- Reply to this email directly, view it on GitHub https://github.com/muschellij2/mscstts/issues/13, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGPLQUAAXN5Y7NVOQXPLDV5OARDANCNFSM6AAAAAAQI5LGQM . You are receiving this because you are subscribed to this thread.Message ID: @.<mailto:@.>>

- Reply to this email directly, view it on GitHubhttps://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmuschellij2%2Fmscstts%2Fissues%2F13%23issuecomment-1274384441&data=05%7C01%7Cfan.xiong%40doh.wa.gov%7C0a8e2e3331b74d3a03d508daab69b2b0%7C11d0e217264e400a8ba057dcc127d72d%7C0%7C0%7C638010767711313248%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2B6cPvvgU%2FmPQuZ035SL5ugnlhdZGZ%2FMYVThECMZp2uA%3D&reserved=0, or unsubscribehttps://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAPCTHITMX2L44D54PQ32TZDWCUWJ7ANCNFSM6AAAAAAQI5LGQM&data=05%7C01%7Cfan.xiong%40doh.wa.gov%7C0a8e2e3331b74d3a03d508daab69b2b0%7C11d0e217264e400a8ba057dcc127d72d%7C0%7C0%7C638010767711313248%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=gkkgwAWE9S7RJVDwbW3SM8p2tHtZbHOneZ8RkhgS5Cc%3D&reserved=0. You are receiving this because you authored the thread.Message ID: @.**@.>>

howardbaik commented 1 year ago

@doh-FXX0303 I'm getting the same error code (forbidden HTTP 403 error) when running ms_synthesize().

Were you able to figure something out?

doh-FXX0303 commented 1 year ago

@doh-FXX0303 I'm getting the same error code (forbidden HTTP 403 error) when running ms_synthesize().

Were you able to figure something out?

@howardbaek Nope, but I was able to do it successfully through python using azure-cognitiveservices-speech

howardbaik commented 1 year ago

Thanks for sharing.

I'll take a deep dive into ms_synthesize(), and if I can't figure something out, I'll use reticulate and use the Microsoft Cognitive Services Speech SDK for Python, as you did.

howardbaik commented 1 year ago

@doh-FXX0303 I was able to fix the function: https://github.com/muschellij2/mscstts/pull/14

Basically, I had to change the variable name from xname to voice on Line 72, add a couple headers to POST(), and include Bearer in front of the token.

howardbaik commented 1 year ago

@doh-FXX0303 I figured out the reason for the HTTP Forbidden 403 error. mscstts::ms_synthesize() was using an invalid voice (for the specific region) in the HTTP request. For example, for the westus region, it was using a voice name that was not supported in that region inside the SSML. This caused the server to reject the HTTP request.

So, I wrote a rebooted version of this package, called mscstts2, that resolves this issue. It'd be great if you tried it out and gave us feedback.

doh-FXX0303 commented 1 year ago

@doh-FXX0303 I figured out the reason for the HTTP Forbidden 403 error. mscstts::ms_synthesize() was using an invalid voice (for the specific region) in the HTTP request. For example, for the westus region, it was using a voice name that was not supported in that region inside the SSML. This caused the server to reject the HTTP request.

So, I wrote a rebooted version of this package, called mscstts2, that resolves this issue. It'd be great if you tried it out and gave us feedback.

I may not be able to test it anymore. My Azure subscription is gone. So, hopefully, some other user of this package could try. Otherwise, it may be some time before I go back to Azure and this project.

howardbaik commented 1 year ago

@doh-FXX0303 I don't know what your situation is, but this package doesn't require any particular subscription. As I explained in Getting an API Key, you can choose the free version with Free F0, and can still use the package.