YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
WhisperDevice.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_WHISPERDEVICE_H
7#define YARP_WHISPERDEVICE_H
8
9#include <curl/curl.h>
10#include <iomanip> // for std::setw, std::hex, std::setfill
11#include <iostream>
12#include <vector>
13#include <cstdlib>
14#include <sstream>
15#include <iterator>
16#include <cstring>
17
18#include <nlohmann/json.hpp>
19
22#include <yarp/os/all.h>
23#include <yarp/sig/Sound.h>
24
26
42{
43public:
45 WhisperDevice(const WhisperDevice&) = delete;
46 WhisperDevice(WhisperDevice&&) noexcept = delete;
47 WhisperDevice& operator=(const WhisperDevice&) = delete;
48 WhisperDevice& operator=(WhisperDevice&&) noexcept = delete;
49 ~WhisperDevice() override = default;
50
51 // DeviceDriver
52 bool open(yarp::os::Searchable& config) override;
53 bool close() override;
54
55 // yarp::dev::ISpeechTranscription
56 yarp::dev::ReturnValue setLanguage(const std::string& language="auto") override;
57 yarp::dev::ReturnValue getLanguage(std::string& language) override;
58 yarp::dev::ReturnValue transcribe(const yarp::sig::Sound& sound, std::string& transcription, double& score) override;
59
60private:
61 std::string m_url;
62 std::string m_apiKey;
63 struct curl_slist *headers{nullptr};
64
65 std::vector<uint8_t> _createWavHeader(int sampleRate, int numSamples);
66 static size_t _writeCallback(void *contents, size_t size, size_t nmemb, std::string *output);
67};
68
69#endif // YARP_WHISPERDEVICE_H
This class is the parameters parser for class WhisperDevice.
whisperDevice: A yarp device for speech synthesis using azure openai APIs
yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current language set for speech transcription.
yarp::dev::ReturnValue transcribe(const yarp::sig::Sound &sound, std::string &transcription, double &score) override
Performs the speech transcription.
yarp::dev::ReturnValue setLanguage(const std::string &language="auto") override
Sets the language for speech transcription.
bool close() override
Close the DeviceDriver.
WhisperDevice(WhisperDevice &&) noexcept=delete
WhisperDevice(const WhisperDevice &)=delete
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Interface implemented by all device drivers.
A generic interface for speech transcription.
STL namespace.
The main, catch-all namespace for YARP.
Definition dirs.h:16