mirror of https://github.com/OpenVidu/openvidu.git
'lang' parameter in subscribeToSpeechToText method
parent
8a8cce27f5
commit
38a8681d17
|
@ -651,12 +651,13 @@ export class Session extends EventDispatcher {
|
|||
* @returns A Promise (to which you can optionally subscribe to) that is resolved if the speech-to-text subscription
|
||||
* was successful and rejected with an Error object if not.
|
||||
*/
|
||||
subscribeToSpeechToText(stream: Stream): Promise<void> {
|
||||
subscribeToSpeechToText(stream: Stream, lang: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.openvidu.sendRequest(
|
||||
'subscribeToSpeechToText',
|
||||
{
|
||||
connectionIds: [stream.connection.connectionId]
|
||||
connectionIds: [stream.connection.connectionId],
|
||||
lang
|
||||
},
|
||||
(error, response) => {
|
||||
if (!!error) {
|
||||
|
@ -1318,9 +1319,18 @@ export class Session extends EventDispatcher {
|
|||
/**
|
||||
* @hidden
|
||||
*/
|
||||
async onSpeechToTextMessage(event: { streamId: string; connectionId: string; sessionId: string, text: string, reason: string, raw: string }): Promise<void> {
|
||||
async onSpeechToTextMessage(event: {
|
||||
timestamp?: Date;
|
||||
streamId: string;
|
||||
connectionId: string;
|
||||
sessionId: string;
|
||||
text: string;
|
||||
reason: string;
|
||||
raw: string;
|
||||
lang: string;
|
||||
}): Promise<void> {
|
||||
const connection = await this.getConnection(event.connectionId, 'No connection found for connectionId ' + event.connectionId);
|
||||
const ev = new SpeechToTextEvent(this, connection, event.text, <any>event.reason.toLowerCase(), event.raw);
|
||||
const ev = new SpeechToTextEvent(this, connection, event.text, <any>(event.reason).toLowerCase(), event.raw, event.lang);
|
||||
this.ee.emitEvent('speechToTextMessage', [ev]);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,15 +45,22 @@ export class SpeechToTextEvent extends Event {
|
|||
*/
|
||||
raw: string;
|
||||
|
||||
/**
|
||||
* Language ISO 639-1 code of the recognized text. This will be the same as the language provided
|
||||
* in method [[Session.subscribeToSpeechToText]] method
|
||||
*/
|
||||
lang: string;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
constructor(target: Session, connection: Connection, text: string, reason: 'recognizing' | 'recognized', raw: string) {
|
||||
constructor(target: Session, connection: Connection, text: string, reason: 'recognizing' | 'recognized', raw: string, lang: string) {
|
||||
super(false, target, 'speechToTextMessage');
|
||||
this.connection = connection;
|
||||
this.text = text;
|
||||
this.reason = reason;
|
||||
this.raw = raw;
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -150,6 +150,7 @@ public class ProtocolElements {
|
|||
|
||||
public static final String SUBSCRIBETOSPEECHTOTEXT_METHOD = "subscribeToSpeechToText";
|
||||
public static final String SUBSCRIBETOSPEECHTOTEXT_CONNECTIONIDS_PARAM = "connectionIds";
|
||||
public static final String SUBSCRIBETOSPEECHTOTEXT_LANG_PARAM = "lang";
|
||||
|
||||
public static final String UNSUBSCRIBEFROMSPEECHTOTEXT_METHOD = "unsubscribeFromSpeechToText";
|
||||
public static final String UNSUBSCRIBEFROMSPEECHTOTEXT_CONNECTIONIDS_PARAM = "connectionIds";
|
||||
|
|
|
@ -188,7 +188,7 @@ public abstract class SessionManager {
|
|||
public abstract void onVideoData(Participant participant, Integer transactionId, Integer height, Integer width,
|
||||
Boolean videoActive, Boolean audioActive);
|
||||
|
||||
public abstract void onSubscribeToSpeechToText(Participant participant, Integer transactionId,
|
||||
public abstract void onSubscribeToSpeechToText(Participant participant, Integer transactionId, String lang,
|
||||
JsonArray connectionIds);
|
||||
|
||||
public abstract void onUnsubscribeFromSpeechToText(Participant participant, Integer transactionId,
|
||||
|
|
|
@ -1201,7 +1201,7 @@ public class KurentoSessionManager extends SessionManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribeToSpeechToText(Participant participant, Integer transactionId, JsonArray connectionIds) {
|
||||
public void onSubscribeToSpeechToText(Participant participant, Integer transactionId, String lang, JsonArray connectionIds) {
|
||||
sessionEventsHandler.onUnsubscribeToSpeechToText(participant, transactionId, new OpenViduException(
|
||||
Code.WRONG_OPENVIDU_EDITION, "Speech To text requires OpenVidu Pro/Enterprise edition"));
|
||||
}
|
||||
|
|
|
@ -735,7 +735,8 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
|
|||
Participant participant = sanityCheckOfSession(rpcConnection, "subscribeToSpeechToText");
|
||||
JsonArray connectionIds = (JsonArray) RpcHandler.getParam(request,
|
||||
ProtocolElements.SUBSCRIBETOSPEECHTOTEXT_CONNECTIONIDS_PARAM);
|
||||
sessionManager.onSubscribeToSpeechToText(participant, request.getId(), connectionIds);
|
||||
String lang = RpcHandler.getStringParam(request, ProtocolElements.SUBSCRIBETOSPEECHTOTEXT_LANG_PARAM);
|
||||
sessionManager.onSubscribeToSpeechToText(participant, request.getId(), lang, connectionIds);
|
||||
}
|
||||
|
||||
private void unsubscribeFromSpeechToText(RpcConnection rpcConnection, Request<JsonObject> request) {
|
||||
|
|
Loading…
Reference in New Issue