• הרשמה
    • התחברות
    • חיפוש
    • דף הבית
    • אינדקס קישורים
    • פוסטים אחרונים
    • קבלת התראות מהדפדפן
    • משתמשים
    • חיפוש בהגדרות המתקדמות
    • חיפוש גוגל בפורום
    • ניהול המערכת
    • ניהול המערכת - שרת private

    עבודה עם ימות ראוטר2 בnodejs | מוזיקה בהמתנה לחישוב של השרת

    פורום מפתחים API
    2
    2
    135
    טוען פוסטים נוספים
    • מהישן לחדש
    • מהחדש לישן
    • הכי הרבה הצבעות
    תגובה
    • הגיבו כנושא
    התחברו בכדי לפרסם תגובה
    נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
    • M
      MGM IVR נערך לאחרונה על ידי MGM IVR

      עריכה:
      בסוף הסתדרתי, אני פשוט מתמלל אחרי כל בקשה, ואז זה יוצא שניה- שתיים לפני כל שאלה, וזה פחות מורגש,
      אך עדיין אשמח לתשובה ממי שיודע איך משמיעים מוזיקה בהמתנה

      אני התחלתי לעבוד עם הספריה
      https://github.com/ShlomoCode/yemot-router2

      ואני מסתבך איך להשמיע ללקוח מוזיקה בהמתנה

      התהליך הוא שאני לוקח ממנו פרטים בטלפון (חלקם הקלטות וחלקם הקשות),
      ואז אני מעבד את כל ההקלטות בשרת עם זיהוי דיבור של גוגל, ומכניס לdb,
      הזיהוי דיבור לוקח כמה שניות כי זה כמה הקלטות,
      השאלה היא איך אפשר להשמיע בינתיים ללקוח מוזיקה מהמאגר של ימות המשיח

      כרגע אני מנסה ככה
      ככה אני לוקח מהם את הפרטים שאני צריך מהם

          let firstName  = await call.read([{ type: 'text', data: `אנא הקלט את שמך הפרטי וסולמית לסיום` }], 'record', {
              no_confirm_menu: true
          });
      
          let lastName  = await call.read([{ type: 'text', data: `אנא הקלט את שם המשפחה וסולמית לסיום` }], 'record', {
              no_confirm_menu: true
          });
      
         let bankNumber = await call.read([{ type: 'text', data: 'אנא הקש ב 2 ספרות את מספר הבנק' }], 'tap', {
              max_digits: 2,
              min_digits: 2
          });
          
          let branchNumber = await call.read([{ type: 'text', data: 'אנא הקש ב 3 ספרות את מספר הסניף' }], 'tap', {
              max_digits: 3,
              min_digits: 3
          });
      
          let accountNumber = await call.read([{ type: 'text', data: 'אנא הקש את מספר החשבון וסולמית לסיום' }], 'tap', {
              max_digits: 15,
              min_digits: 4
          });
      

      ישר אחרי זה בקוד, אני מנסה להחזיר את המוזיקה בהמתנה

          call.id_list_message([{ type: 'music_on_hold', data: {
              musicName: 'ztomao',
              maxSec: 10 
          }}],{prependToNextAction: true});
        
      

      אחרי זה יש לי פונקציה שמורידה את ההקלטות, ושולחת לתמלול,

      
      function encodeBase64(file) {
        return fs.readFileSync(file, { encoding: 'base64' });
      }
      
      async function downloadFile(url, fileName) {
          const response = await axios({
              method: 'GET',
              url: url,
              responseType: 'stream',
          });
      
          const writer = fs.createWriteStream(fileName);
      
          response.data.pipe(writer);
      
          return new Promise((resolve, reject) => {
              writer.on('finish', resolve);
              writer.on('error', reject);
          });
      }
      
      
      export async function stt(urlAudio) {
          const apiKey = '@@@@@@@@';
          const url = `https://speech.googleapis.com/v1/speech:recognize?key=${apiKey}`;
          
          let fileName = urlAudio.split('/').pop();
          await downloadFile(urlAudio, `./${fileName}`);
          const audioContentBase64 = encodeBase64(`./${fileName}`);
          const data = {
              config: {
                  encoding: 'LINEAR16',
                  languageCode: 'he-IL',
              },
              audio: {
                  content: audioContentBase64,
              },
          };
          return new Promise((resolve, reject) => {
              axios.post(url, data)
              .then(response => {
                  const results = response.data.results || [];
                  let transcription = ''; // Store transcription result
                  results.forEach(result => {
                      const alternatives = result.alternatives || [];
                      alternatives.forEach(alternative => {
                          transcription += alternative.transcript + ' '; // Append transcription
                      });
                  });
                  resolve(transcription.trim()); // Resolve with transcription
              })
              .catch(error => {
                  reject(error); // Reject with error
              });
          });
      }
      
      
      

      שאני משתמש בה בעצם ככה

         let data = {
              phone: call.phone,
              firstName: await stt(`https://www.call2all.co.il/ym/api/DownloadFile?token=${token}&path=ivr2:/${firstName}`),
              lastName: await stt(`https://www.call2all.co.il/ym/api/DownloadFile?token=${token}&path=ivr2:/${lastName}`),
              bankNumber: bankNumber,
              branchNumber: branchNumber,
              accountNumber: accountNumber
          }
      

      ואז מגיע הבדיקה מול הdb האם הערך קיים או לא והחזרה כטקסט של התוצאה

      let re = await addAvrech(data);
      call.id_list_message([{ type: 'text', data: re}],{prependToNextAction: true});
      await call.hangup();
      return;
      

      הבעיה שהוא ממתין לתשובה, ומתמלל את הכל, ולא משמיע את המוזיקה בהמתנה,
      אחרי זה הוא אומר שיש שגיאה, ואז מקריא את התשובה שחזרה מהdb, ומנתק את השיחה

      צ תגובה 1 תגובה אחרונה תגובה ציטוט 1
      • צ
        צדיק תמים מומחה @MGM IVR נערך לאחרונה על ידי צדיק תמים

        @MGM-IVR
        prependToNextAction: true אומר בעצם "תוסיף את ההודעה לתור"
        כלומר לא חוזרת שום תשובה באופן מיידי, אלא כאשר תגיע לread הבא, יישלח הודעה משורשרת (עם &) שכוללת:

        1. את ההודעה/ות שבתור
        2. את הread עצמו

        ככה בערך זה נראה בקוד של הספריה

          this.#responsesTextQueue = {
                    pull: () => {
                        const queueText = this.#_responsesTextQueue;
                        this.#_responsesTextQueue = '';
                        return queueText;
                    },
                    push: (newResText) => {
                        this.#_responsesTextQueue += `${newResText}&`;
                    }
            };
        
            id_list_message (messages, options = {}) {
                const responseTxt = `id_list_message=${messagesCombined}`;
                if (prependToNextAction) {
                    this.#responsesTextQueue.push(responseTxt); // 👈👈
                } else {
                    this.send(this.#responsesTextQueue.pull() + responseTxt + '&');
                }
            }
        
        async read() {
        this.send(this.#responsesTextQueue.pull() + responseText);
        }
        

        זה לא ממש נוח, אבל ככה זה עובד מהגלגול הקודם של הספריה (לפני הfork שלי), ואני לא רוצה לשבור קוד קיים.

        תגובה 1 תגובה אחרונה תגובה ציטוט 1
        • פוסט ראשון
          פוסט אחרון