Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
CMAKE_MINIMUM_REQUIRED(
VERSION
2.8
)
PROJECT(
speech
)
FIND_LIBRARY(
APPKIT_LIBRARY
AppKit
)
FIND_PATH(
APPKIT_INCLUDE_DIR
AppKit/AppKit.h
)
INCLUDE_DIRECTORIES(
${APPKIT_INCLUDE_DIR}
)
INCLUDE_DIRECTORIES(
.
)
ADD_LIBRARY(
speech
speaker_impl.mm
speaker.mm
)
TARGET_LINK_LIBRARIES(
speech
${APPKIT_LIBRARY}
)
SET_TARGET_PROPERTIES(
speech
PROPERTIES
COMPILE_FLAGS -fobjc-arc
)
ADD_EXECUTABLE(
speak
speak.cpp
)
TARGET_LINK_LIBRARIES(
speak
speech
)
#include <speaker.hpp>
int main(int argc, char *argv[])
{
your::friends::library::speech::speaker speaker;
for (int word = 1; word < argc; ++word)
{
speaker.speak(
argv[word]
);
while (
speaker.is_speaking()
);
}
}
#ifndef YOUR_FRIENDS_LIBRARY_SPEECH_SPEAKER_HPP
#define YOUR_FRIENDS_LIBRARY_SPEECH_SPEAKER_HPP
#include <speaker_impl_fwd.hpp>
#include <string>
namespace your
{
namespace friends
{
namespace library
{
namespace speech
{
class speaker
{
public:
speaker();
~speaker();
void
speak(
std::string const &
);
bool
is_speaking() const;
private:
speaker_impl * const pimpl_;
};
}
}
}
}
#endif
#include <speaker.hpp>
#include <speaker_impl.hpp>
#include <Foundation/NSString.h>
your::friends::library::speech::speaker::speaker():
pimpl_(
new your::friends::library::speech::speaker_impl
)
{
}
your::friends::library::speech::speaker::~speaker()
{
delete pimpl_;
}
void
your::friends::library::speech::speaker::speak(
std::string const & string
)
{
[pimpl_->synth_ startSpeakingString:
[NSString stringWithUTF8String:
string.c_str()
]
];
}
bool
your::friends::library::speech::speaker::is_speaking() const
{
return [pimpl_->synth_ isSpeaking];
}
#ifndef YOUR_FRIENDS_LIBRARY_SPEECH_SPEAKER_IMPL_HPP
#define YOUR_FRIENDS_LIBRARY_SPEECH_SPEAKER_IMPL_HPP
#import <AppKit/NSSpeechSynthesizer.h>
namespace your
{
namespace friends
{
namespace library
{
namespace speech
{
struct speaker_impl
{
public:
speaker_impl();
NSSpeechSynthesizer * const synth_;
};
}
}
}
}
#endif
#include <speaker_impl.hpp>
your::friends::library::speech::speaker_impl::speaker_impl():
synth_(
[[NSSpeechSynthesizer alloc] init]
)
{
}
#ifndef YOUR_FRIENDS_LIBRARY_SPEECH_SPEAKER_IMPL_FWD_HPP
#define YOUR_FRIENDS_LIBRARY_SPEECH_SPEAKER_IMPL_FWD_HPP
namespace your
{
namespace friends
{
namespace library
{
namespace speech
{
struct speaker_impl;
}
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment