blog - 201210のエントリ

AppleのText To Speechは,テキストファイルを人間の声で読み上げてくれるソフトウェアだが,AppleScriptを使えば、読み上げた声をaiffなどのオーディオファイルに保存することができる.

以下のスクリプトは、Web上にあるテキストをダウンロードして、テキストファイルに保存し,それをTTSで読み上げた音声をaiffファイルに保存する.
このスクリプトをTwitToSpeechというフォルダに保存し、デスクトップに置いて使用する.
処理の流れは以下の通り.

読み上げボイスは,Kathy
このスクリプトを保存するフォルダ名(TwitToSpeech)とフォルダの置き場(desktop)を指定する.
 読み上げられるテキストファイルtextPath(test.txt)と音声ファイルaiffPath(test.aiff)がこのフォルダに保存される.
tweetURLで目的とするURLを指定する。

try - end tryでは、"URL Access Scripting"を使って、tweetURLで指定したWeb上のコンテンツをテキストファイルtextPath(test.txt)に上書き保存する。

テキストファイルの中身をシェルのcatコマンドを使って、tweetWordsに入れて、TTSで読み上げた音声をオーディオファイルaiffPath(test.aiff)に保存する.

最後のコメントアウトされている行は,テキストの内容をダイアログボックスに表示させて確認するときに使う.

set voiceOfHuman to "Kathy"
set folderPath to (path to desktop folder from user domain as text) & "TwitToSpeech:"
set textPath to folderPath & "test.txt" as Unicode text
set aiffPath to folderPath & "test.aiff"
set tweetURL to "http://blossom.media.t-kougei.ac.jp/~kuha/tweet02.php?c=5&d=0"

try
	with timeout of 30 seconds
		tell application "URL Access Scripting"
			activate
			download tweetURL to file textPath replacing yes with progress
		end tell
	end timeout
on error
	display dialog "Download Error"
end try

set tweetWords to do shell script "cat " & (POSIX path of textPath)
say tweetWords using voiceOfHuman saving to aiffPath
--display dialog stringOfMessage

ただし、"URL Access Scripting" は、OSX Lionから廃止になったので,上のスクリプトが使えるのは、Snow Leopardまで.
Lion以降からは、OSXのコマンドのcurlを使って,do shell script "curl http://・・・ "などとする.

以下の例は、curlを使った例。
ちなみに、curlは、Lionだけでなく、Snow Leopard以前でも使える。

tweetURLで指定したURLの内容をcurlで、tweetWordsに入れ、write でtextPathで指定したテキストファイルに保存している。

set voiceOfHuman to "Kathy"
set folderPath to (path to desktop folder from user domain as text) & "TwitToSpeech:"
set textPath to folderPath & "test.txt" as Unicode text
set aiffPath to folderPath & "test.aiff"
set tweetURL to "http://blossom.media.t-kougei.ac.jp/~kuha/tweet02.php?c=5&d=0"

try
	with timeout of 30 seconds
		set tweetWords to do shell script "curl " & tweetURL
	end timeout
on error
	display dialog "Download Error"
end try

try
	set saveFile to open for access file textPath with write permission
	set eof of saveFile to 0
	write tweetWords to saveFile
end try
close access saveFile

say tweetWords using voiceOfHuman saving to aiffPath
--display dialog stringOfMessage

Google Maps APIのMap styleの変更

カテゴリ : 
コンピュータ » プログラミング
執筆 : 
kuha 2012-10-26 20:30
Google Maps APIのMap featuresは、道路、景色、ビルなど地図上の要素で、これらを指定して、地図のスタイルやデザインを変えることができる。
https://developers.google.com/maps/documentation/javascript/reference?hl=ja#MapTypeStyleFeatureType

これらのstyleを個別に指定するには、Stylersのcolor, hue, saturationなどの要素をMap featureごとに指定すればよい。

以下の例は、stylesをグローバルにJSON形式で定義し、paintRoad()とpaintLandscape()という関数で、colorを別個に指定している。

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 10px; padding: 10px }
      #map_canvas { height: 100% }
    </style>
    <title>Google Maps API Styled Maps サンプル</title>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    //<![CDATA[
			   
var map;
var latlng_koogei = new google.maps.LatLng(35.463536,139.32945);
// stylesをグローバルで定義
var styles = [
	{
		featureType: "road",
		elementType: "geometry",
		stylers: [
			{ color: "" },
		]
	},
	{
		featureType: "landscape",
		elementType: "geometry",
		stylers: [
			{ color: "" },
		]
	}
];

function initialize() {
	//地図の設定
	var opts = {
		zoom: 15,
		center: latlng_koogei,
		mapTypeId: google.maps.MapTypeId.ROADMAP
		//mapTypeId: google.maps.MapTypeId.SATELLITE
		};
	map = new google.maps.Map(document.getElementById("map_canvas"), opts);
}// initialize()の最後

function paintRoad() {
	var value = document.getElementById("mapcolor1").value;
	styles[0].stylers[0].color = value;
	map.setOptions({styles: styles});
}
function paintLandscape() {
	var value = document.getElementById("mapcolor2").value;
	styles[1].stylers[0].color = value;
	map.setOptions({styles: styles});
}

//]]>
</script>
  </head>
  <body onLoad="initialize()">
    <p>Google Maps API Geo Codingサンプル</p>
    <div id="map_canvas" style="width:500px; height:300px"></div>
    <div>
      道路の色を#rrggbbで入力:
      <input id="mapcolor1" type="textbox" value="#ff0000">
      <input type="button" value="Paint" onclick="paintRoad()">
    </div>
    <div>
      景色の色を#rrggbbで入力:
      <input id="mapcolor2" type="textbox" value="#00ff00">
      <input type="button" value="Paint" onclick="paintLandscape()">
    </div>
  </body>
</html>

NIME 2013 May 27-30, Daejeon + Seoul, Korea

カテゴリ : 
イベント
執筆 : 
kuha 2012-10-19 20:59
NIME 2013の日程がアナウンスされている。

May 27-30, 2013 | Daejeon + Seoul, Korea Republic
Call for participation
http://nime2013.kaist.ac.kr/call_for_participation/

Important dates
Paper/performance/installation submissions and workshop proposals due: February 1, 2013
Review notification: March 16, 2013
Camera-ready paper deadline: April 21, 2013
Google Maps APIで表示する地図は、styleOptionsを使ったスタイル付き地図で配色などのグラフィカルな要素を変更できる。

Google Maps JavaScript API v3 Styled Maps
https://developers.google.com/maps/documentation/javascript/styling?hl=ja

stylesというJSON形式のデータで、オプションを指定する。
たとえば、

var styles = [
{
	featureType: "road",
	elementType: "geometry",

	stylers: [
	{ color: "#FF00FF" },
	]
}
];

のようにJSONで定義されたデータで構成される。[]で囲われた部分が配列で、{}で囲われた部分がオブジェクトである。

これにアクセスするには、JSONはオブジェクトと配列を組み合わせた形なので、オブジェクトの部分は、.(ドット)でプロパティ値を書いてつなぎ、配列の部分は[0]などのように、添字の数字で指定する。

alert(styles[0].stylers[0].color);

styles[0].stylers[0].color = "#FF0000";

などとする。
この例は、最初の行で、color属性の値を画面に出力し、
次の行で、color属性の値を書き込んでいる。
おもしろそうな講演です。

東京芸術大学先端芸術表現科特別講義
題目「言語,情動,芸術」

講師 岡ノ谷一夫 先生(東京大学教授,東京芸術大学客員教授)
日時 2012年10月17日(水)18:00 -
会場 東京芸術大学 上野キャンパス 美術学部中央講義棟第3講義室
入場無料 予約不要

概要
芸術は,言語と並んで人間と人間以外の動物を分かつものと言える。しかし,ヒトと動物の非連続性を指摘することではなく,非連続性に対して連続的な説明を与えるのが生物学の立場であり,芸術への科学の接近法である。芸術の至近要因と究極要因を,前適応と創発の概念のもと生物学的に理解する枠組みを検討する。
スポンサードリンク
検索

blogカテゴリ一覧

blogger一覧

blogアーカイブ