-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshiny.R
100 lines (82 loc) · 2.75 KB
/
shiny.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
library(shiny)
library(shinybusy)
#Libraries
library(httr)
library(jsonlite)
library(dplyr)
library(readr)
library(tuneR)
library(stringr)
#The following is a command line only representation
# greeting(init_prompt = read_file('./prompts/try.txt'), userFirstMessage= "
#
# Hello, good morning bro.
# ", maxLengthInput= 75)
#
#
#
#
# chatWithAI(currentMessage = "Tell me a joke about Docker",
# maxLengthInput = 210)
#
#
#
#
#
# renderFullConvoSpeech()
conversation_history <- c()
source('./shiny_functions/functions.R')
ui <- fluidPage(
titlePanel("Voice Recording App"),
selectInput("recordType", "Select Record Type", choices = c("greeting", "continuedMessage")),
actionButton("startRecording", "Start Recording"),
actionButton("stopRecording", "Stop Recording"),
numericInput("responseLength", "Desired Response Length", value = 128, min = 1, max = 512, step = 1),
actionButton("sendToAPI", "Send to API"),
textOutput("recordingStatus"),
textOutput("apiResponse"),
add_busy_spinner()
)
server <- function(input, output, session) {
recording <- FALSE
currentRecording <- NULL
observeEvent(input$startRecording, {
if (!recording) {
recording <<- TRUE
if (input$recordType == "greeting") {
currentRecording <<- "greetingR.wav"
} else if (input$recordType == "continuedMessage") {
currentRecording <<- "test.wav"
}
# Start recording
system(paste0("rec -r 16000 ", currentRecording, " &"))
output$recordingStatus <- renderText("Recording started")
}
})
observeEvent(input$stopRecording, {
if (recording) {
recording <<- FALSE
# Stop recording
system(paste0("pkill -f 'rec -r 16000 ", currentRecording, "'"))
output$recordingStatus <- renderText("Recording stopped")
}
})
observeEvent(input$sendToAPI, {
if (!is.null(currentRecording)) {
# Call the appropriate function based on recording type
if (currentRecording == "greetingR.wav") {
api_response <- greeting(init_prompt = read_file('./prompts/init_alt.txt'),
userFirstMessage= greetingVoice(), maxLengthInput = input$responseLength)
renderResponse <- read_file('./greeting.txt')
renderResponse <- as.character(renderResponse)
} else if (currentRecording == "test.wav") {
api_response <- process_recorded_message(desiredLength = input$responseLength,
voiceID = "p293")
renderResponse <- read_file('./currentResponse.txt')
renderResponse <- as.character(renderResponse)
}
output$apiResponse <- renderText(renderResponse)
}
})
}
shinyApp(ui = ui, server = server)