我有一个对话流聊天机器人,它通过Twilio与商业用户的Whatsapp通信。
我想增强聊天机器人的能力,并允许whatsapp用户也能够发送语音消息。
发送到Twilio的WhatsApp语音媒体消息有一个带有媒体文件位置的URI参数,但此URI没有文件扩展名。如何提取文件以将其发送到语音转文本服务(Google或AWS),以便将其转录为文本,然后将其发送到Dialogflow以进行意图识别
你知道我该怎么做吗?
媒体消息的Twilio消息日志:
Request Inspector
+ Expand All
POST
https://xxxxxxxxxxxx
2021-04-27 08:35:39 UTC502
Request
URL
ParametersShow Raw
MediaContentType0 "audio/ogg"
SmsMessageSid "MMea4e6bcb3a9654a03d8d2a607c6d4cdd"
NumMedia "1"
ProfileName "xxxxx"
SmsSid "MMea4e6bcb3a9654a03d8d2a607c6d4cdd"
WaId "xxxxxxxxx"
SmsStatus "received"
Body ""
To "whatsapp:+32460237475"
NumSegments "1"
MessageSid "MMea4e6bcb3a9654a03d8d2a607c6d4cdd"
AccountSid "ACef27744806d8f8e68f25211b2ba8af60"
From "whatsapp:+32474317098"
MediaUrl0 "https://api.twilio.com/2010-04-01/Accounts/ACef27744806d8f8e68f25211b2ba8af60/Messages/MMea4e6bcb3a9654a03d8d2a607c6d4cdd/Media/ME27fbc66d47d8de49f1ae00e433884097"
ApiVersion "2010-04-01"
Message TextShow Raw
sourceComponent "14100"
httpResponse "502"
url "https://xxxxxxxxx"
ErrorCode "11200"
LogLevel "ERROR"
Msg "Bad Gateway"
EmailNotification "false"发布于 2021-04-29 22:29:35
我认为这个用例不需要扩展,您可能需要生成文本的语言代码,并且可能需要转录服务的AudioEncoding和sample rating。
以下是我的代码中的一些示例,用于实现语音到文本和DialogFlow的转换。AWS和微软非常相似
//for ibm watson
RecognizeOptions recognizeOptions = new RecognizeOptions.Builder()
.model(RecognizeOptions.Model.ES_ES_NARROWBANDMODEL)
.audio(new ByteArrayInputStream(bytes))
.contentType(HttpMediaType.AUDIO_WAV)
.build();
// google speech to text
RecognitionConfig config = RecognitionConfig.newBuilder()
.setSampleRateHertz(48000)
.setLanguageCode(langcode)
.setEncoding(RecognitionConfig.AudioEncoding.OGG_OPUS)
.build();
// Dialogflow (sending audio directly)
InputAudioConfig inputAudioConfig = InputAudioConfig
.newBuilder()
.setLanguageCode(langcode)
.setSampleRateHertz(sampleRateHertz)
.build();最后,在所有情况下,您发送给服务的不是一个文件,而是一个字节数组(某种程度上)
无论如何,即使内容类型和文件扩展名之间没有一对一的关系,请求中的参数"MediaContentType0“也会给你一个很好的起点:”音频/ogg“。
https://stackoverflow.com/questions/67282665
复制相似问题