Esempio n. 1
0
        public void Say(string sentense, SupportedLanguage language)
        {
            EnsureSynthesisModule();
            if (language == SupportedLanguage.NotSpecified)
            {
                language = _synthesisProfiles.Keys.First();
            }
            if (!_synthesisProfiles.ContainsKey(language))
            {
                throw new LanguageNotSupportedException(language);
            }
            _synthesisModule.SetProfile(_synthesisProfiles[language]);
            _synthesisModule.BuildSentence(1, sentense);

            int nbuffers = _synthesisModule.QueryBufferNum(1);

            for (int i = 0; i < nbuffers; i++)
            {
                PXCMAudio           audio = _synthesisModule.QueryBuffer(1, i);
                PXCMAudio.AudioData audioData;
                audio.AcquireAccess(PXCMAudio.Access.ACCESS_READ, PXCMAudio.AudioFormat.AUDIO_FORMAT_PCM, out audioData);
                RealSenseAudioPlayer.Play(audioData, _synthesisProfiles[language].outputs);
                audio.ReleaseAccess(audioData);
            }
            _synthesisModule.ReleaseSentence(1);
        }
    /**
     *  @brief The function retrieves the synthesized speech as an Unity AudioClip object.
     *  @param[in] name			The audio clip name
     *  @param[in] sid			The sentence identifier
     *  @return the AudioClip instance, or null if there is any error.
     */
    public AudioClip QueryAudioClip(String name, Int32 sid)
    {
        int nsamples = QuerySampleNum(sid);

        if (nsamples == 0)
        {
            return(null);
        }
        ProfileInfo pinfo;

        QueryProfile(out pinfo);
        AudioClip clip = AudioClip.Create(name, nsamples * pinfo.outputs.nchannels,
                                          pinfo.outputs.nchannels, pinfo.outputs.sampleRate, false, false);
        int nbuffers = QueryBufferNum(sid);

        for (int i = 0, offset = 0; i < nbuffers; i++)
        {
            PXCMAudio           audio = QueryBuffer(sid, i);
            PXCMAudio.AudioData data;
            pxcmStatus          sts = audio.AcquireAccess(PXCMAudio.Access.ACCESS_READ, PXCMAudio.AudioFormat.AUDIO_FORMAT_IEEE_FLOAT, out data);
            if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                break;
            }
            float[] samples = data.ToFloatArray();
            clip.SetData(data.ToFloatArray(), offset);
            offset += samples.Length;
            audio.ReleaseAccess(data);
        }
        return(clip);
    }
        public int abc(Byte[] databuff, int index, PXCMAudio.AudioInfo audioinfo)
        {
            PXCMAudio.AudioInfo ainfo = new PXCMAudio.AudioInfo()
            {
                bufferSize = 8820,                                   // max number of bytes
                format     = PXCMAudio.AudioFormat.AUDIO_FORMAT_PCM, // audio sample format
                sampleRate = 44100,                                  // sampling rate in Hz
                nchannels  = 2,                                      // number of channels
            };

            PXCMAudio audio = session.CreateAudio(ainfo);

            if (audio == null)
            {
                Debug.Log("RSSDK: CreateAudio error !");
                return(0);
            }

            audioinfo = audio.QueryInfo();
            PXCMAudio.AudioData data;
            int num_samples = 0;

            audio.AcquireAccess(PXCMAudio.Access.ACCESS_READ, out data);
            data.ToByteArray().CopyTo(databuff, (long)index);
            num_samples = (int)(data.dataSize);
            audio.ReleaseAccess(data);
            audio.Dispose();
            return(num_samples);
        }
 public bool RenderAudio(PXCMAudio audio)
 {
     PXCMAudio.AudioData adata;
     pxcmStatus sts = audio.AcquireAccess(PXCMAudio.Access.ACCESS_READ, PXCMAudio.AudioFormat.AUDIO_FORMAT_PCM, out adata);
     if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) return false;
     bw.Write(adata.ToByteArray());
     audio.ReleaseAccess(adata);
     return true;
 }
Esempio n. 5
0
        public bool RenderAudio(PXCMAudio audio)
        {
            PXCMAudio.AudioData adata;
            pxcmStatus          sts = audio.AcquireAccess(PXCMAudio.Access.ACCESS_READ, PXCMAudio.AudioFormat.AUDIO_FORMAT_PCM, out adata);

            if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                return(false);
            }
            bw.Write(adata.ToByteArray());
            audio.ReleaseAccess(adata);
            return(true);
        }
Esempio n. 6
0
    // Use this for initialization
    void Start()
    {
        _pxcmSenseManager = PXCMSenseManager.CreateInstance();

        if (_pxcmSenseManager == null)
        {
            Debug.LogError("SenseManager Initialization Failed");
        }
        else
        {
            int         nbuffers;
            int         nsamples;
            AudioSource aud  = GetComponent <AudioSource>();
            String      name = "test";
            Int32       sid  = 1;

            _pxcmSenseManager.session.CreateImpl <PXCMSpeechSynthesis>(out tts);
            PXCMSpeechSynthesis.ProfileInfo pinfo;
            tts.QueryProfile(0, out pinfo);
            pinfo.language = PXCMSpeechSynthesis.LanguageType.LANGUAGE_US_ENGLISH;
            tts.SetProfile(pinfo);
            tts.BuildSentence(1, "The year is 2098.  Interstellar space travel was made possible in 2045.  But space travel is dangerous.  Human life support systems for interdimensional transport are costly and high risk.  The majority of trade ships are unmanned and piloted remotely using hyper dimensional virtual reality.  Use the voice command initialize to begin, or click the play button.");

            nsamples = tts.QuerySampleNum(sid);

            if (nsamples != 0)
            {
                tts.QueryProfile(out pinfo);
                clip = AudioClip.Create(
                    name,
                    nsamples * pinfo.outputs.nchannels,
                    pinfo.outputs.nchannels,
                    pinfo.outputs.sampleRate,
                    false
                    );

                nbuffers = tts.QueryBufferNum(sid);

                for (int i = 0, offset = 0; i < nbuffers; i++)
                {
                    PXCMAudio           audio = tts.QueryBuffer(sid, i);
                    PXCMAudio.AudioData data;
                    pxcmStatus          sts = audio.AcquireAccess(
                        PXCMAudio.Access.ACCESS_READ,
                        PXCMAudio.AudioFormat.AUDIO_FORMAT_IEEE_FLOAT,
                        out data
                        );

                    if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        break;
                    }

                    float[] samples = data.ToFloatArray();

                    clip.SetData(data.ToFloatArray(), offset);

                    offset += samples.Length;

                    audio.ReleaseAccess(data);
                }

                aud.clip = clip;
                aud.Play();
            }
        }

        tts.Dispose();
    }
        private void recording()
        {
            //Default values
            string output_file_name = timestamp + ".wav";

            // Get a memory stream for the audio data, wrapped with a big try catch for simplicity.
            using (MemoryStream writer = new MemoryStream())
            {
                pxcmStatus status = PXCMSession.CreateInstance(out this.session);
                if (status < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    Console.Error.WriteLine("Failed to create the PXCMSession. status = " + status);
                    return;
                }

                PXCMCapture.AudioStream.DataDesc request = new PXCMCapture.AudioStream.DataDesc();
                request.info.nchannels  = 1;
                request.info.sampleRate = 44100;
                uint subchunk2_data_size = 0;

                // Use the capture utility
                using (this.session)
                    using (UtilMCapture capture = new UtilMCapture(this.session))
                    {
                        // Locate a stream that meets our request criteria
                        status = capture.LocateStreams(ref request);
                        if (status < PXCM_STATUS_NO_ERROR)
                        {
                            Console.Error.WriteLine("Unable to locate audio stream. status = " + status);
                            return;
                        }

                        // Set the volume level
                        status = capture.device.SetProperty(PXCMCapture.Device.Property.PROPERTY_AUDIO_MIX_LEVEL, 0.2f);
                        if (status < pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            Console.Error.WriteLine("Unable to set the volume level. status = " + status);
                            return;
                        }

                        Console.WriteLine("Begin audio recording");

                        isRecording = true;
                        // Get the n frames of audio data.
                        while (isRecording)
                        {
                            PXCMScheduler.SyncPoint sp = null;
                            PXCMAudio audio            = null;

                            // We will asynchronously read the audio stream, which
                            // will create a synchronization point and a reference
                            // to an audio object.
                            status = capture.ReadStreamAsync(out audio, out sp);
                            if (status < PXCM_STATUS_NO_ERROR)
                            {
                                Console.Error.WriteLine("Unable to ReadStreamAsync. status = " + status);
                                return;
                            }

                            using (sp)
                                using (audio)
                                {
                                    // For each audio frame
                                    // 1) Synchronize so that you can access to the data
                                    // 2) acquire access
                                    // 3) write data while you have access,
                                    // 4) release access to the data

                                    status = sp.Synchronize();
                                    if (status < PXCM_STATUS_NO_ERROR)
                                    {
                                        Console.Error.WriteLine("Unable to Synchronize. status = " + status);
                                        return;
                                    }

                                    PXCMAudio.AudioData adata;

                                    status = audio.AcquireAccess(PXCMAudio.Access.ACCESS_READ, PXCMAudio.AudioFormat.AUDIO_FORMAT_PCM, out adata);
                                    if (status < PXCM_STATUS_NO_ERROR)
                                    {
                                        Console.Error.WriteLine("Unable to AcquireAccess. status = " + status);
                                        return;
                                    }

                                    byte[] data = adata.ToByteArray();
                                    int    len  = data.Length;
                                    writer.Write(data, 0, len);

                                    // keep a running total of how much audio data has been captured
                                    subchunk2_data_size += (uint)(adata.dataSize * BYTES_PER_SAMPLE);

                                    audio.ReleaseAccess(ref adata);
                                }
                        }
                        Console.WriteLine("End audio recording");
                    }

                // The header needs to know how much data there is. Now that we are done recording audio
                // we know that information and can write out the header and the audio data to a file.
                using (BinaryWriter bw = new BinaryWriter(File.Open(output_file_name, FileMode.Create, FileAccess.Write)))
                {
                    bw.Seek(0, SeekOrigin.Begin);
                    WriteAudioHeader(bw, subchunk2_data_size, (short)request.info.nchannels, request.info.sampleRate);
                    bw.Write(writer.ToArray());
                }
            }
        }