1.0.27 • Published 3 years ago

@heitech/voice-library-npm v1.0.27

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Table of contents

How it works

It uses Web Speech API. Note that browser support for this API is currently limited, with Chrome having the best experience - see supported browsers for more information.

RoomClient for listening from microphone, convert to text (+ translate to the choosen language). It also provides functions to speak the selected text.

Usage

In React.tsx:

Import { RoomClient } from `@heitech/voice-library-npm`

const App = () => {
    UseEffect(()=>{
        const voiceRecognition = new RoomClient((textRecognizing:string)=>{callbackonTextRecognizing(textRecognizing)},  (textRecognized)=>{callbackOnTextRecognized(textRecognized)});
    },[])
    return ()
}

You can get text with 2 functions callbackOnTextRecognizing, callbackOnTextRecognized:

textRecognizing: string

textRecognized

.privTranslations: 
{
    privMap{
        privKeys: 'vi',
        privValues: 'Xin chào'
    }
}

Init listening + speaking:

Import { RoomClient } from `@heitech/voice-library-npm`

const Room = () => {

  const callbackonTextRecognizing = (e: string) => {
    console.log('callbackonTextRecognizing ', e);

  }
  const callbackOnTextRecognized = (e: Object) => {
    console.log('callbackOnTextRecognized ', e);
  }

   UseEffect(() => {
    const voiceRecognition = new RoomClient(
      (textRecognizing: string) => callbackonTextRecognizing(textRecognizing),
      (textRecognized: object) => callbackOnTextRecognized(textRecognized)
    );

    // init listener + speaker and translation
    voiceRecognition.initTranslation(YOUR_KEY,'vi-VN', 'en-US');
  }, [])

  return (
    // JSX here
  )
}

  
  • log
callbackonTextRecognizing  Hello
callbackonTextRecognizing  Hello we
callbackonTextRecognizing  Hello we are 
callbackonTextRecognizing  Hello we are heitech
callbackOnTextRecognized  
    TranslationRecognitionResult {
        privDuration: 18000,
        privText: "Hello we are heitech",
        privTranslations: {
            privMap: {
                privValues: ['Xin chào chúng tôi là heitech']
            }
        }
    }

action.ts

export const onSpeech = (data: string) => ({
  type: TYPES.POST_SPEECH,
  payload: data
});

export const onSpeechFinished = (data: string) => ({
  type: TYPES.POST_SPEECH_FINISHED,
  payload: data
});

reducer.ts

switch (action.type) {
    case TYPES.POST_SPEECH:
      return {
        ...state,
        speeching: action.payload,
        error: '',
      };
      
    case TYPES.POST_SPEECH_FINISHED:
      return {
        ...state,
        textRecognized: action.payload,
        error: '',
      };

    default:
      return state;
  }

Room.tsx

const Room = () => {
  const dispatch = useDispatch();

 UseEffect(() => {
    const voiceRecognition = new RoomClient(
      (textRecognizing: string) => dispatch(onSpeech(textRecognizing)),
      (textRecognized: object) => dispatch(onSpeechFinished(textRecognizing))
    );

    voiceRecognition.initTranslation(key,'vi-VN', 'en-US');
  }, [])


  return (
  // JSX here
  )
 }

Others functions Client Room:

  • voiceRecognition.changeLanguage(language)
  • voiceRecognition.changetranslationLanguage(language)
  • voiceRecognition.close()
  • voiceRecognition.open()

Lists devices:

voiceRecognition.listDevices().then(data => {
  console.log(data);
})

Room client devices functions:

  • voiceRecognition.enableMic()
  • voiceRecognition.enableWebcam()
  • voiceRecognition.disableMic()
  • voiceRecognition.disableWebcam()

Git repo example:

Contributors

From Heitech company :

License

MIT

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago