Skip to content

Instantly share code, notes, and snippets.

@JulianKniephoff
Created March 27, 2011 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JulianKniephoff/889411 to your computer and use it in GitHub Desktop.
Save JulianKniephoff/889411 to your computer and use it in GitHub Desktop.
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.mm
)
TARGET_LINK_LIBRARIES(
speech
${APPKIT_LIBRARY}
)
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 <synthesizer.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:
synthesizer * const synth_;
};
}
}
}
}
#endif
#include <speaker.hpp>
#import <AppKit/AppKit.h>
your::friends::library::speech::speaker::speaker():
synth_(
[[NSSpeechSynthesizer alloc] init]
)
{
}
your::friends::library::speech::speaker::~speaker()
{
[synth_ release];
}
void
your::friends::library::speech::speaker::speak(
std::string const & string
)
{
[synth_ startSpeakingString:
[NSString stringWithUTF8String:
string.c_str()
]
];
}
bool
your::friends::library::speech::speaker::is_speaking() const
{
return [synth_ isSpeaking];
}
#ifndef YOUR_FRIENDS_LIBRARY_SPEECH_SYNTHESIZER_HPP
#define YOUR_FRIENDS_LIBRARY_SPEECH_SYNTHESIZER_HPP
#if __OBJC__
#import <Appkit/AppKit.h>
#endif
namespace your
{
namespace friends
{
namespace library
{
namespace speech
{
#if __OBJC__
typedef NSSpeechSynthesizer synthesizer;
#else
typedef void synthesizer;
#endif
}
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment