Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
API de voz web que devuelve la transcripción anterior

tengo este servicio en angular para traducir voz a texto a traves de webspeech

 import { Injectable } from '@angular/core'; declare var webkitSpeechRecognition: any; @Injectable({ providedIn: 'root' }) export class VoiceRecognitionService { recognition = new webkitSpeechRecognition(); isListening = false; public text = ''; public tempWords : any; public transcript_arr = []; public confidence_arr = []; constructor() { } getTranscriptValue() { return this.transcript_arr; } getConfidenceValue() { return this.confidence_arr; } init() { this.recognition.continuous = true; this.recognition.interimResults = false; this.recognition.maxAlternatives = 1; this.recognition.lang = 'en-US'; this.recognition.addEventListener('result', (e:any) => { let last = e.results.length - 1; let temp_trans = e.results[last][0].transcript; let confidence = e.results[last][0].confidence; this.confidence_arr.push(confidence); this.transcript_arr.push(temp_trans); const transcript = Array.from(e.results) .map((result:any) => result[0]) .map((result) => result.transcript) .join(''); this.tempWords = transcript; }); } start() { if(this.isListening==false) { this.isListening = true; this.recognition.start(); } this.recognition.addEventListener('end', (condition:any) => { if (!this.isListening) { this.recognition.stop(); } else { this.wordConcat() this.recognition.start(); } }); } stop() { this.isListening = false; this.wordConcat(); this.recognition.stop(); } reinit() { this.transcript_arr=[]; this.confidence_arr=[]; this.tempWords=''; this.text=''; } wordConcat() { this.text = this.text + ' ' + this.tempWords + '.'; this.tempWords = ''; } }

Llamo a esta función de servicio desde el archivo .ts como si llamara a this.service.init() al inicio y luego this.service.start() después de eso llamo a this.service.stop() y this.service.reinit() pero Todavía obtengo valores antiguos con los nuevos valores en el result event listener en la variable temp_trans . No quiero valores antiguos. Quiero valores nuevos si lo detengo a través this.service.stop() .

Cualquier solución es muy apreciada. Gracias

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Intente borrar también temp_trans cuando reinicie.

 @Injectable({ providedIn: 'root' }) export class VoiceRecognitionService { recognition = new webkitSpeechRecognition(); isListening = false; temp_trans = ''; public text = ''; public tempWords: any; public transcript_arr: string[] = []; public confidence_arr: string[] = []; constructor() { } getTranscriptValue() { return this.transcript_arr; } getConfidenceValue() { return this.confidence_arr; } init() { this.recognition.continuous = true; this.recognition.interimResults = false; this.recognition.maxAlternatives = 1; this.recognition.lang = 'en-US'; this.startListening(); } startListening() { this.recognition.addEventListener('result', (e: any) => { let last = e.results.length - 1; this.temp_trans = e.results[last][0].transcript; let confidence = e.results[last][0].confidence; this.confidence_arr.push(confidence); this.transcript_arr.push(this.temp_trans); this.tempWords = Array.from(e.results) .map((result: any) => result[0]) .map((result) => result.transcript) .join(''); }); } stopListening() { this.recognition.removeEventListener('result', () => ()); } start() { if (!this.isListening) { this.isListening = true; this.recognition.start(); } this.recognition.addEventListener('end', (condition: any) => { if (!this.isListening) { this.recognition.stop(); } else { this.wordConcat(); this.recognition.start(); } }); } stop() { this.isListening = false; this.wordConcat(); this.recognition.stop(); this.stopListening(); } reinit() { this.startListening(); this.transcript_arr = []; this.confidence_arr = []; this.temp_trans = ''; this.tempWords = ''; this.text = ''; } wordConcat() { this.text = this.text + ' ' + this.tempWords + '.'; this.tempWords = ''; } }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda