Documente Academic
Documente Profesional
Documente Cultură
# Speech-To-Text-Orange credentials": {
url <- "https://stream.watsonplatform.net/speech-to-text/api"
username <-"55555555-5555-5555-5555-55555555" # you need your own - STT service
credentials from bluemix
password <- "44444444444" # you need your own - STT service credentials from
bluemix
username_password = paste(username,":",password,sep="")
###### FUNCTION - ANalyze AUDIO WAV file with IBM Watson Speech to Text service
watson.speech_to_text.recognize <- function(audio_file)
{ return(POST(url=paste(url,"/v1/recognize",sep=""),
authenticate(username,password),
add_headers("Content-Type"="audio/wav"),
body = (file = upload_file(audio_file))
))} #works # hope this helps you with syntax!
#### FUNCTION TO TIDY UP the STT response - just export the TRANSCRIPT ONLY
stt_transcript_only <- function(raw)
{
data <- as.data.frame(strsplit(as.character(raw),"\\n"))
data <- data[c(7), ] # for now, grab just what we want
data <- paste(data) # kill levels, - fyi this nukes confidence % info (may want
later)
data <- gsub(" ","",data) # remove excessive whitespace 0 cannot use ALL
[[punct]] here
data <- gsub("\\\\","",data) # remove punct we dont like
data <- gsub("\"","",data) # remove punct we dont like
data <- gsub("transcript","",data) # remove excessive whitespace
data <- gsub(":","",data) # remove excessive whitespace - later: Improve this
tidy step.
return(data)
}
## TESTS OK
response <- watson.speech_to_text.recognize("ryan_rasp_pi1.wav") #make sure your
WAV is in the working directory getwd() to check
response # takes about 5 seconds - this is not best method # You're looking for a
"200"
#content(response,"text") # raw results
transcript <- stt_transcript_only(content(response,"text"))
transcript # extracted the core translation (deleted a bunch more)
########## LICENSE
http://www.apache.org/licenses/LICENSE-2.0